vue中proxyTable配置方法
vue项目中,本地调试时使用用proxyTable代理转发后端接口的方法。1.当后端接口有统一path时如后端接口为http:172.168.0.1:8081/api/user,且每个接口都有统一的/api开始。可以设置:proxyTable:{'/api': {target: 'http:172.168.0.1:8081',//目标接口域changeOrigin: true,//是否跨域secu
·
vue项目中,本地调试时使用用proxyTable代理转发后端接口的方法。
1.当后端接口有统一path时
如后端接口为http://172.168.0.1:8081/api/user,且每个接口都有统一的/api开始。可以设置:
proxyTable:{
'/api': {
target: 'http:172.168.0.1:8081', //目标接口域
changeOrigin: true, //是否跨域
secure: false,//当是https的时候改成false
pathRewrite: { //当有统一path此处可不写,效果一样
'^/api': '/api' //重写接口
}
}
1.当后端接口没有统一path时
若后端的接口开头的path不统一时,按如下设置:
前端调接口时,人为给所有接口拼上 /api,比如后端接口为http://172.168.0.1:8081/user,前端请求时加上/api变成http://172.168.0.1:8081/api/user,然后proxyTable配置为:
proxyTable:{
'/api': {
target: 'http:172.168.0.1:8081', //目标接口域
changeOrigin: true, //是否跨域
secure: false,//当是https的时候改成false
pathRewrite: {
'^/api': '/ ' //重写接口
}
}
pathRewrite也可以设置为:
pathRewrite: {
'^/api': ' '
}
更多推荐
已为社区贡献1条内容
所有评论(0)