【发布时间】:2017-11-16 08:43:49
【问题描述】:
我正在做一个端到端的分离项目,我的后端已经完成。 现在遇到了跨域问题
我的 Vue 代码:
// config/index.js
proxyTable: {
"/api":{
target: "http://localhost:8001",
changeOrigin: true,
secure: false,
pathRewrite:{
"^/api":"/api"
}
}
this.$axios.get("/api/user/login?username=xx&password=123")
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
如果我在浏览器中访问http://localhost:8001/api/user/login?username=xx&password=123,它会返回我编写的 JSON。
但它在 axios 中不起作用,错误为 GET http://localhost:8085/api/user/login?username=xx&password=123 504 (Gateway Timeout)。
【问题讨论】:
-
可能是 CORS 问题,请检查您的网络选项卡,在 chrome/firefox 控制台中查看该请求的错误。
-
错误提示`尝试代理时出错:localhost:8085/api/user/login?username=xx&password=123`
-
不要检查控制台,检查网络标签
-
状态码是 504 Gateway Timeout ,响应是 Error occurred while trying to proxy to: localhost:8085/api/user/login?username=xx&password=123
-
我的意思是检查你的浏览器控制台,打开它去
network标签并点击response标签
标签: vue.js cross-domain frontend axios