axios post method, the background can not receive data

  1. After the basic post request, you see Request is transmitted in the form of Payload parameters, not form-data format. At this point add the head headers.
this.axios.post('url',{
    userCardId: promptValue
}).then(res => {

 })

Here Insert Picture Description Here Insert Picture Description
2. Add headers: { 'Content-Type': 'application / x-www-form-urlencoded'}; the following results, Form Data passed an object.

this.axios({
    method:'post',
    url:'url',
    data:{userCardId:promptValue},
    headers:{'Content-Type':'application/x-www-form-urlencoded'},
}).then(res =>{
                      
}) 

Here Insert Picture Description Here Insert Picture Description
3. Continue adding transformRequest part, do data conversion. At this time, the rear end can receive the data.

this.axios({
    method:'post',
    url:'url',
    data:{userCardId:promptValue},
    headers:{'Content-Type':'application/x-www-form-urlencoded'},
    transformRequest:[function (data) {
        let ret = ''
        for (let it in data) {
            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
         }
            return ret
     }],
 }).then(res =>{
                    
 }) 

Here Insert Picture Description Here Insert Picture Description
https://github.com/Gesj-yean/vue-demo-collection documented use more outstanding plug-ins. Students have time to look at my top blog can thank you very much.

Published 27 original articles · won praise 4 · Views 2832

Guess you like

Origin blog.csdn.net/qq_39083496/article/details/89382774