配置文件路径:
config/index.js
proxyTable配置:
proxyTable: {
// 这里配置 '/api' 就等价于 target , 你在链接里访问 /api === http://localhost:8089
'/api': {
target: 'http://localhost:8089',
// secure: true, // 如果是 https ,需要开启这个选项
// 是否是跨域请求?肯定是啊,不跨域就没有必要配置这个proxyTable了.
changeOrigin: true,
loglevel: 'debug',
// 这里是重写链接,比如真是接口里不包含 /api,就需要这样配置
pathRewrite: {
'^/api': '',
// 和下边两种写法,因人而异根据需求。
// 等价于 /api + / == http://localhost:8089/
// 如果写为 '^/api' : '/api'
// 等价于 /api + /api == http://localhost:8089/api
// 这里的 /api == http://localhost:8089
}
},
'/sp': {
target: 'http://localhost:8090',
changeOrigin: true,
loglevel: 'debug',
pathRewrite: {
'^/sp': '',
}
}
}
methods方法中的服务调用方式
axios.get('/api/check').then(function(res) {
})
axios.get('/ipa/he').then(function(res) {
})
springboot后端服务
@RequestMapping("/check")
public String check(){
System.out.println("hello check");
return "hello check";
}
@RequestMapping("/he")
public String hello(){
System.out.println("hello world");
return "hello world";
}