gpt4 book ai didi

vue.js - Vue devServer 代理没有帮助,我仍然收到 CORS 错误

转载 作者:行者123 更新时间:2023-12-04 20:27:32 25 4
gpt4 key购买 nike

我正在使用 @vue/cli 3.x 并且在我的 vue.config.js 中我有这个:

devServer: {
proxy: {
"/api": {
ws: true,
changeOrigin: true,
target: "http://localhost:8080"
}
}
}

但我不断收到 CORS 错误:

Access to XMLHttpRequest at 'http://localhost:8080/api' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.



任何的想法?

最佳答案

看起来问题出在 axios 配置上。

我有这个定义:axios.defaults.baseURL = "http://localhost:8080/api";我把它改成了 axios.defaults.baseURL = "api";
它有效。

module.exports = {
...
devServer: {
proxy: {
"^/api": {
target: url,
ws: true,
changeOrigin: true
}
}
},
}

关于vue.js - Vue devServer 代理没有帮助,我仍然收到 CORS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55607326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com