美文网首页
axios post请求 数据转格式

axios post请求 数据转格式

作者: 摩诘居士 | 来源:发表于2018-05-16 11:27 被阅读0次

全局拦截器内添加pos t数据转格式方法

http.interceptors.request.use(function (config) { //拦截器对url做转码,解决ie下url带中文参数乱码问题

config.url  = encodeURI(config.url);

if (config.url=='http://139.159.233.113/oauth/token') {

  config.transformRequest=[function (data) {

        let ret = '';

        for (let it in data) {

          ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'

        }

        return ret;

      }]

}

  return config;

}, function (error) {

  return Promise.reject(error);

});

相关文章

网友评论

      本文标题:axios post请求 数据转格式

      本文链接:https://www.haomeiwen.com/subject/kvhpdftx.html