axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.headers.get['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.transformRequest = [function (data) {
let ret = ''
for (let it in data) {
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
}
return ret
}]
main.js页面上加入上面这段代码。
本文介绍如何在main.js中配置Axios默认的请求头和转换请求数据为application/x-www-form-urlencoded格式的方法。通过设置默认请求头和自定义转换函数,确保POST和GET请求都以统一的数据格式进行。
8427

被折叠的 条评论
为什么被折叠?



