Axios various request parameter transfer formats

Time:2021-1-8

HTTP parameter transfer mode

header、query、body
1⃣️ header
 Request Headers
 cookie: xxx
2⃣️ query
url?id=1
3⃣️ body
request payload

🚩 axios

One A kind of Head pass ginseng
axios.post(url, data, {
    headers: {
        'token': token
        }
    }).then(function(response) {
       console.log(response)
    });
2⃣️ axios#get(url[, config])
// url?id=1
axios.get(url,{
    params: {
      id: 1
    }
}).then(function (response) {
    console.log(response);
})
3⃣️ axios#post(url[, data[, config]])
// request payload {id:1}
axios.post(url, {
    id: 1
}).then(function (response) {
    console.log(response);
})
4⃣️ axios#delete(url[, config])
// url?id=1
axios.delete(url, {
    params: {
        id: 1
    }
}).then(function (response) {
    console.log(response);
})


// request payload {id:1}
axios.delete('url', params = {
    data: {
        id: 1
    }
}).then(function (response) {
    console.log(response);
})
5⃣️ axios#put(url[, config])
// url?name='yumi'
// request payload {id:1}
axios.put('url', {
      id: 1
    }, {
      params: {
        name: 'yumi'
      }
}).then(function (response) {
    console.log(response);
})