Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

开发环境npm run serve可以跨域访问,正式环境打包npm run build后不能跨域访问 #24

Closed
GitHub1527 opened this issue Jun 2, 2020 · 3 comments

Comments

@GitHub1527
Copy link

GitHub1527 commented Jun 2, 2020

config配置了
publicPath: './',
'/api': {
target: 'http://127.0.0.1:8083/',
*****
}
axios配置访问
this.$axios.post('/api/testData', {}).
开发环境没错,正式环境前端tomcat8081报错,java后台还是8083端口接口
http://127.0.0.1:8081/api/testData
Failed to load resource: the server responded with a status of 404 (Not Found)。
访问地址没有代理成http://127.0.0.1:8083/testData
这些参数都加了,想知道这个怎么解决?

@woai3c
Copy link
Owner

woai3c commented Jun 2, 2020

config配置了
publicPath: './',
'/api': {
target: 'http://127.0.0.1:8083/',


}
axios配置访问
this.$axios.post('/api/testData', {}).
开发环境没错,正式环境前端tomcat8081报错,java后台还是8083端口接口
http://127.0.0.1:8081/api/testData
Failed to load resource: the server responded with a status of 404 (Not Found)。
访问地址没有代理成http://127.0.0.1:8083/testData
这些参数都加了,想知道这个怎么解决?

这只是开发环境的配置,打包后的文件是放在服务器下的。所以接口地址要和服务器地址一致。

@GitHub1527
Copy link
Author

前后端分离打包,java接口地址和前端服务器不一致,有没有配置?有的话告知下,谢谢哈

@woai3c
Copy link
Owner

woai3c commented Jun 3, 2020

前后端分离打包,java接口地址和前端服务器不一致,有没有配置?有的话告知下,谢谢哈

没有特殊配置,你在前端写的API 地址多少就是多少。你可以创建一个工具函数,生成一个 axios 实例,然后把你后端的接口地址写上去,这样所有的接口都能使用。

@woai3c woai3c closed this as completed Jun 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants