1、vue-cli创建的项目中设置:config目录下的index.js修改如下:
proxyTable: {
'/devApi': {
target: 'http://192.168.0.88:8080', //这里后台的地址模拟的;应该填写你们真实的后台接口
changOrigin: true, //允许跨域
pathRewrite: {
/* 重写路径,当我们在浏览器中看到请求的地址为:
http://localhost:8080/devApi/service/login 时
实际上访问的地址是:http://192.168.0.88:8080/service/login,因为重写了 /devApi
*/
'^/devApi': ''
}
},
},
2、通过@vue/cli创建的项目中设置:根目录下的vue.config.js下修改如下:
proxyTable: {
proxy: {
'/devApi': {
target: 'http://192.168.0.88:8080', //这里后台的地址模拟的;应该填写你们真实的后台接口
changOrigin: true, //允许跨域
pathRewrite: {
/* 重写路径,当我们在浏览器中看到请求的地址为:
http://localhost:8080/devApi/service/login 时
实际上访问的地址是:http://192.168.0.88:8080/service/login,因为重写了 /devApi
*/
'^/devApi': ''
}
},
// 这里可以设置多个代理
},
}
3、设置axios的baseURL
axios.defaults.baseURL = '/devApi'
if (process.env.NODE_ENV === 'production') {
axios.defaults.baseURL = 'http://192.168.0.88:8080'
}
本文暂时没有评论,来添加一个吧(●'◡'●)