vue2-all-test icon indicating copy to clipboard operation
vue2-all-test copied to clipboard

请教一下axios跨域的问题

Open pcloth opened this issue 7 years ago • 1 comments

我将代码中的config.withCredentials = true打开了。

axios.interceptors.request.use(config => { // Do something before request is sent config.withCredentials = true // 需要跨域打开此配置 // post提交 data存在 并且 data不是FormData对象时对数据进行json化处理 // if(config.method==='post' && config.data && config.data.constructor !== FormData){ // config.data = qs.stringify(config.data) // config.headers['Content-Type'] = 'application/x-www-form-urlencoded' // } // 开启loading动画 store.dispatch('popup/loading/showLoading') return config }, function(error) { // Do something with request error return Promise.reject(error) })

后台设置了rst.headers['Access-Control-Allow-Origin'] = '*'

控制台报错信息: Error: Network Error at createError (eval at <anonymous> (app.js:1834), <anonymous>:15:15) at XMLHttpRequest.handleError (eval at <anonymous> (app.js:1813), <anonymous>:87:14)

pcloth avatar May 19 '17 08:05 pcloth

这个报错信息不是跨域错误,可能是接口返回的数据格式有问题

SirM2z avatar Jun 05 '17 03:06 SirM2z