您现在的位置是:网站首页>前端技术>VueVue

vue 使用axios发送post请求出现 Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

神夜2020-08-21 10:41:21Vue4128人已围观文章来源:神夜个人博客

简介axios post请求出现 Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response. 是由于axios post 时需要将字符qs.stringify(query)一下就好了

axios post请求出现 Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.  是由于axios post 时需要将字符qs.stringify(query)一下就好了,在响应拦截器里面设置

config.data = qs.stringify(config.data);



import qs from 'qs';

axios.interceptors.request.use(config => {    
    config.headers.token = 'token';
    config.data = qs.stringify(config.data);
    return config
}, error => {
    return Promise.reject(error);
})


站点信息

  • 建站时间:2017-10-24
  • 网站程序:Hsycms 3.0
  • 文章统计:511条
  • 微信公众号:扫描二维码,关注我们