vue.config.js
module.exports = {
devServer: {
proxy: {
//接口代理
‘/api’: { //这个名字要和下边的一致
target: `http:localhost:8080` //你的项目接口地址
changeOrigin: true,
pathRewrite: {
'^/api' : '/' //这个名字要和上边的一致
}
}
}
}
}
global.js
在定义多个后台接口时:
const url = { //你定义的路径参数
admin: "/api/admin", //这里的`api`和vue.config.js中
client: "/api/client" //的`api'是一致的
}
export default{
url //导出你定义的参数
}
main.js
import global from '/gloabl.js' //引号里的是你的文件路径
vue文件中
不同的后台接口对应
url: `${this.global.url.admin}/`+ 你需要的接口路径,
或者
url: `${this.global.url.client}/`+ 你需要的接口路径,