第一種方法
var params = new URLSearchParams();
params.append('a', 1);
params.append('b', 2);
params.append('c', 3);
this.$axios.post(url,params,{
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(res => {
console.log(res)
}
.catch(error => {
console.log(error)
})
第二種方法
通過下載安裝qs來解決
nnpm install --save axios vue-axios qs
在請(qǐng)求的頁面引入qs
import qs from 'qs'
請(qǐng)求代碼
this.biography={'a':1,'b':2,'c':3}
var obj=qs.stringify(this.biography)
axios.post(url,obj,
headers:{
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
}
})
.then(res=>{
console.log(res)
}
.catch(error => {
console.log(error)
})