用cors解决跨域问题,但是仍然出现问题
相关代码
// 服务器app.js
app.use(cors({
origin:['http://localhost:8080'],
methods:['GET','POST'],
alloweHeaders:['Content-Type', 'Authorization']
}));
//前端获取数据页面
axios.get("http://localhost:3000/goods").then(response => {
console.log(response)
})
仍然报错
错误信息
但是Network上有数据出来
1、你只允许了
'Content-Type', 'Authorization'
2、没有允许错误中的
Credentials
,但是请求头中有该参数3、请按照你的请求头,列出所有要允许的跨域参数
4、也就是说
vue
的axios
的请求头里面 withCredentials,要设置为withCredentials: false