场景:
常见的跨域报错,一般都是由后端进行setHeader/*什么的。但是现在这种情况就是后端说他们做了处理。但是我这边请求还是报错。

withCredentials:
with-credentials用来设置是否发送cookie,如果为true就会在跨域请求时候携带cookie,如果是同一个域名则设置什么都无妨,但是如果不是同一个域名下/外部接口,携带了cookie的话,后端就不能将Access-Control-Allow-Origin设置为*。因为设置为*时cookie不会出现在http的请求头里。
修改方法:
// 创建axios实例
const service = axios.create({
    baseURL: process.env.VUE_APP_URL, // 测试环境
    withCredentials: true,
    timeout: 20000 // 请求超时时间
})
// request拦截器
service.interceptors.request.use(config => {
      如果是外部的请求则设置为false
    if (config.url && config.url.indexOf('/data/board/distributed') > 0){ 
  config.withCredentials = false
    }
    config.headers['Content-Type'] = 'application/json; charset=UTF-8'
    if (JSON.parse(localStorage.getItem('user'))) {
        config.headers['Authorization'] = "dowsure " + JSON.parse(localStorage.getItem("user")).token;
    }
    return config
}, error => {
    // Do something with request error
    Promise.reject(error)
})
或者(我没有试过)
将Content-Type: 'application/json'改为Content-Type: 'application/x-www-form-urlencoded'















![[开源] 基于GRU的时间序列预测模型python代码](https://img-blog.csdnimg.cn/direct/b4eda21ff10944fba9afff8afc864c23.png)


