今天小编就为大家分享一篇Vue axios 将传递的json数据转为form data的例子,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
修改main.js文件中axios的配置:
在发送请求前将数据用qs模块转化
修改请求头的Content-Type='application/x-www-form-urlencoded'
具体配置如下:
import axios from 'axios' import qs from 'qs' // 添加请求拦截器 axios.interceptors.request.use(function (config) { if(config.method!='get'){ config.data=qs.stringify(config.data); } config.headers['Content-Type'] = 'application/x-www-form-urlencoded'; return config; },function (error) { return Promise.reject(error) })
以上就是Vue axios 将传递的json数据转为form data的例子的详细内容,更多请关注0133技术站其它相关文章!