写在Vue.config.js文件中
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
devServer:{
port:8080,//启动的端口
proxy:{
//可以配置多个代理信息 每一个代理使用key:value形式
//代理的名字代表请求路径 login代表前端访问他访问地址为http://localhost:8080/user/xxx
'/user':{
//出发代理后把请求转发到哪
//转发后的地址为http://localhost:8081/user/xxx
target : 'http://localhost:8081',
//转发后的地址重写规则是什么
pathRewrite : {
//以/user开头的原路径转换成空 就是去掉
'^/user' : ''
}
}
}
}
})