VUE—axios单独设置form表单提交/application/x-www-form-urlencoded
引入import axios from "axios";请求位置axios.post(url,{comtents:this.con,relationNum:this.value},{headers: {"Content-Type": "appli...
·
引入
import axios from "axios";
请求位置
axios
.post(
url,
{
comtents:this.con,
relationNum:this.value
},
{
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
//transformRequest允许在向服务器发送前,修改请求数据
transformRequest: [
function(data) {
let ret = "";
for (let it in data) {
ret +=
encodeURIComponent(it) +
"=" +
encodeURIComponent(data[it]) +
"&";
}
return ret;
}
]
}
)
.then(res => {
console.log(res.data); //返回的数据
})
.catch(err => {
console.log(err);
that.$toast.fail("网络请求失败");
});
更多推荐
已为社区贡献4条内容
所有评论(0)