Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教一下axios跨域的问题 #2

Open
pcloth opened this issue May 19, 2017 · 1 comment
Open

请教一下axios跨域的问题 #2

pcloth opened this issue May 19, 2017 · 1 comment

Comments

@pcloth
Copy link

pcloth commented May 19, 2017

我将代码中的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)

@SirM2z
Copy link
Owner

SirM2z commented Jun 5, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants