如何将Vue中Axios传递的JSON数据转换为FormData格式?
- 内容介绍
- 文章标签
- 相关推荐
本文共计234个文字,预计阅读时间需要1分钟。
javascript修改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) { // 对数据使用qs模块进行转换 config.data=qs.stringify(config.data); // 修改请求头 config.headers['Content-Type']='application/x-www-form-urlencoded'; return config;}, function (error) { // 对请求错误做些什么 return Promise.reject(error);});
修改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的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。
本文共计234个文字,预计阅读时间需要1分钟。
javascript修改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) { // 对数据使用qs模块进行转换 config.data=qs.stringify(config.data); // 修改请求头 config.headers['Content-Type']='application/x-www-form-urlencoded'; return config;}, function (error) { // 对请求错误做些什么 return Promise.reject(error);});
修改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的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

