我想从项目的后端api访问用户数据,但出现错误:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://http//localhost:4000/api/auth/list. (Reason: CORS request did not succeed).
我以为我可以通过推一个管理令牌来解决这个问题,但不幸的是,它没有起作用。
以下是我在尝试发布令牌时从index.js获得的代码:
let token = 'eyJhb...';
axios.post("http://api.rumaholi.local/api/post", [], {headers: { 'Authorization' : 'Bearer '+ token}}).then(response => {
let comments = response.data;
console.log(comments)
})
//Here is were I try to access the data:
actions: {
async loadUsers({commit}) {
let apiUrl = 'http://localhost:4000/api/auth/list';
let response = await axios.get(apiUrl);
let users = response.data.data;
commit('SET_USERS'), users.map(u => u.attributes)
}
},
mutations: {
SET_USERS(state, users){
state.users = users;
},
}
暂无答案!
目前还没有任何答案,快来回答吧!