在config index.js module.exports 下面的dev裏面配置多域名代理
proxyTable: {
'/api1': {
target: '域名1請求地址',
changeOrigin: true,
pathRewrite: {
'^/api1':'/'
}
},
'/api2': {
target: '域名2請求地址',
changeOrigin: true,
pathRewrite: {
'^/api2':'/'
}
}
},
在main.js裏面加入axios配置
import Axios from 'axios' //導入axios
//將axios掛載到原型上
Vue.prototype.$axios = Axios;
在頁面使用時
this.$axios.get("/api1/"+url).then(res => {
if(res.status==200){
console.log(res.data);
}
})