已经在网上找了很多种方法,最后还是这种方法对我有用
总共更改的文件有三个:
1. 更改main.js文件
添加下面代码
//设置请求的根路径,地址为后端地址
axios.defaults.baseURL = 'http://localhost:8088'
2.更改config/index.js
添加下面代码
proxyTable: {
'/apis': {
// 此处的写法,目的是为了 将 /apis 替换成 http://localhost:8088
target: 'http://localhost:8088',//这个地址是后端的地址
// 允许跨域
changeOrigin: true,
ws: true,
pathRewrite: {
'^/apis': ''
}
}
},
3.更改config/dev.env.js
添加下面代码
API_HOST: "/apis/"