1.原request请求路径
const requests = axios.create({
baseURL: 'http://localhost:8888', #8888是后端接口
timeout: 5000,
});
2.在根目录(跟src同级)新建vue.config.js
module.exports = {
assetsDir: 'static',
productionSourceMap: false,
devServer: {
open: true,
proxy: {
'/api': {
changeOrigin: true, //开启代理:在本地会创建一个虚拟服务端,然后发送请求数据
target: 'http://localhost:8888', #这里是后端接口
pathRewrite: {
'/api': ''
}
}
}
},
}
3.更改axios请求 地址
const requests = axios.create({
baseURL: 'http://localhost:8080/api/', #改成前端地址\api
timeout: 5000,
});
4.npm run dev(重新加载配置文件) 启动项目