Axios uses delete request to send data parameter passing example.

Note: In the delete method of axios 0.22.0 (not very accurate), configuring the data attribute in config cannot upload payload data, and the axios.request() method can be used instead

For example something like this might not work:

export const LOGIN_OUT= (data: object) => {
    
    
  return http.delete(API.SESSION,{
    
    data})  
}

The reason is:
GET, DELETE method:
that is, the common get/delete request in axios, also known as query request.
For example:

export const GET_ANNOTATION_LIST = (params: object) => {
    
    
  return http.get(API.ANNOTATION_LIST, {
    
     params })
}//这个可以请求
export const GET__LIST = (data: object) => {
    
    
  return http.get(API.LIST, {
    
     data })
}//这个不可以请求,发送不了荷载数据

It is because the second parameter of the get and delete methods is config, which is intended to be used above. When passing values, the data field in config needs to be used. However, some versions do not support writing in this way.

so how to write

Can be replaced by axios.request() method

export const LOGIN_OUT= (data: object) => {
    
    
  return http.request({
    
    
    url:API.SESSION,
    method:"delete",
    data:data
    })
}

insert image description here
Why do you need to write like this, and the design of the axios library is related to the restful standard of the http request specification. If you are interested, it is a specification designed to comply with the standard, the semantics of this request. In fact, from the perspective of http messages, they are completely the same. There is no difference, everyone can send the same information. I can do what you can do, the difference lies in the semantics of the request represented by the method. And the mandatory level of various libraries for this semantics.

Guess you like

Origin blog.csdn.net/m0_46672781/article/details/130322980