使用vue脚手架搭建项目,在项目根目录中创建vue.config.js文件
// vue.config.js
module.exports = {
devServer: {
proxy: {
'/api': {
target: url, // 后端接口路径
changOrigin: true, // 是否允许跨域
pathRewrite: {
'^/api': '' // 路径重写
}
}
}
},
}
// 发送请求的接口改为 /api + 后端接口地址