axios之post请求参数

http的post请求主要有三种类型:

Content-Type: application/json

let data = {"age":"12","name":"aaa"};

axios.post(`${this.$url}/testRequest`,data)

.then(res=>{

    console.log('res=>',res);            

})

 

Content-Type: multipart/form-data

 

let data = new FormData();
data.append('age','12'); data.append('name','aaa'); axios.post(`${this.$url}/testRequest`,data) .then(res=>{ console.log('res=>',res); })

 

Content-Type: application/x-www-form-urlencoded

import qs from 'Qs'

let data = {"age":"12","name":"aaa"};

axios.post(`${this.$url}/testRequest`,qs.stringify({

    data

}))

.then(res=>{

    console.log('res=>',res);            

})

 

posted @ 2023-06-06 19:22  张颖辉  阅读(732)  评论(0编辑  收藏  举报