海綿寶寶撒
2018-11-05 13:17:39
如何實現(xiàn)線上環(huán)境使用setting.host + '/api/sop/',本地dev請求localhost:3000呢?const instance = axios.create({ baseURL: setting.host + '/api/sop/', timeout: 20000, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', },});config
proxyTable: { '/api': {
target: "http://127.0.0.1:3000",
changeOrigin: true,
pathRewrite: { '^/api': ""
}
}
},
1 回答

拉風的咖菲貓
TA貢獻1995條經(jīng)驗 獲得超2個贊
用的vue-resource,理論上思路是一樣的。proxyTable
和nginx
的反向代理是一樣的道理,攔截特定的url
,轉(zhuǎn)發(fā)到其他服務(wù)器。
// config
proxyTable: {
'/api': {
target: 'http://10.0.0.10:8080',
changeOrigin: true,
pathRewrite: {
'^/api': '/api'
}
}
}
// code
this.$http.post('/api/login',{
username: 'xxx',
password: 'xxx'
}).then((response) => {
// ...
}, (response) => {
// ...
});
# 生產(chǎn)環(huán)境 nginx
location /api {
proxy_pass http://10.0.0.10:8080/api;
}
添加回答
舉報
0/150
提交
取消