VueJs Axios Access-Control-Allow-Origin CORS error



我用Vue3和Laravel 8制作了一个网站。我试图使用axios将数据从vue发布到laravel,但我总是收到CORS错误。我什么都试过了,但没有成功。你可以在这里检查错误

将标头添加到axios

addUser() {
axios
.post("http://localhost:8000/api/user/store", this.user, {
headers: { "Access-Control-Allow-Origin": "*" }
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
})
.finally(() => (this.loading = false));
},

向package.json添加代理

"proxy": "http://127.0.0.1:8000",

并尝试了这个:https://enable-cors.org/server_apache.html

我能做什么?

尝试添加

axios.defaults.withCredentials = true;

引导.js

最新更新