import axios from 'axios'
// 使用axios
Vue.prototype.axios = axios;
// 配置公共请求地址
Vue.prototype.baseURL = process.env.API_ROOT;
然后在每个页面请求即可,写法参考:
因为之前一直配置的是公共地址,所以这里只写后面变化的,前面的引用设置的路径即可。
this.axios({
method: "get",
url:`${this.baseURL}/GetAll`,
})
.then((response)=> {
console.log(response)
})
.catch((error)=> {
console.log(error);
});设置完代理别忘了重启服务器。
好了,以上就是vue中配置代理解决跨域的问题。










