我收到的错误消息是
“跨域请求被阻止:同源策略禁止读取http://localhost:5000/user/login上的远程资源。(原因:CORS标头'Access-Control-Allow-Origin'丢失)。“
http-header.js
"import axios from 'axios';
export default axios.create({
baseURL: "http://localhost:5000",
headers: {
'Content-type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
})
AuthService.js
import axios from '../http-header.js'
export default {
login : user => {
return axios.post('/user/login', user)
.then(res => {
if(res.status !== 401)
return res.json().then(data => data)
else {
return {isAuthenticated: false, user: {username: "", role: ""}}
}
})
}
}
答案 0 :(得分:1)
您必须将'Access-Control-Allow-Origin': '*'
添加到您的后端。