this.axios(
{
url:'https://www.easy-mock.com/mock/5c2dc796c8bc2e49abfeaa30/nurse/detailed_infor',
method: 'post',
data: {"key":"值"},
headers:{
'Content-Type':'application/x-www-form-urlencoded'
}
}
)
.then(function (response) {
console.log(response.data.data)
})
.catch(function (error) {
console.log(error)
});
上述这种请求后台body获取的数据实际是 ‘{“key”:“值”}’:‘’ 这样的一个数据
解决办法:
使用qs
let postData = this.$qs.stringify({
"aa":"ss",
"aaaa":"ss"
});
this.axios(
{
url:'https://www.easy-mock.com/mock/5c2dc796c8bc2e49abfeaa30/nurse/detailed_infor',
method: 'post',
data: postData,
headers:{
'Content-Type':'application/x-www-form-urlencoded'
}
}
)
.then(function (response) {
console.log(response.data.data)
})
.catch(function (error) {
console.log(error)
});
安装axios的时候已经安装直接在main.js中使用就行了
import axios from 'axios'
import $qs from 'qs'
Vue.prototype.axios = axios
Vue.prototype.$qs = $qs