config>index.js 里找到 proxyTable{} 在里面添加
'/api': { //此处并非一定和url一致。
target: 'https://test.xxx.com/',//接口地址
changeOrigin: true, //允许跨域
pathRewrite: {
'^/api': ''
}
}
然后在所有接口前加 /api/
//比如原来的
https://test.xxx.com/login
//现在的改为
https://test.xxx.com/api/login
//建议给vue原型添加一个方法
Vue.prototype.returnAPI = function (){
return '/api/'
};
//在调用的时候用此方法修改接口,便于上线后统一修改
npm run dev 需要重新运行