VueJs Axios Access-Control-Allow-Origin CORS 错误

问题描述

我使用 Vue3 和 Laravel 8 创建了一个网站。我尝试使用 axios 将数据从 vue 发布到 Laravel,但我总是遇到 CORS 错误。我尝试了一切,但没有任何效果You can check the error here

向 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;

到 bootstrap.js