参考: https://www.cnblogs.com/tod4/p/16469331.html
1、封装的请求里的baseURL
const instance = axios.create({
baseURL:"/dev-api",
timeout: 5000,
})
2、vue的配置文件vue.config.js文件的配置
module.exports={
// publicPath: "./",
devServer:{
proxy:{
"/dev-api":{
target:'http://www.dianmokj.net',
changeOrigin:true,
pathRewrite: {'^/dev-api':''},
ws: true
}
}
}
}
3、请求的使用
async axiosdata() {
console.log("wql1111")
this.$request.request({
method: "get",
url: "/zashangmao/cockpit_index.php",
data:{
act:'get_token'
}
})
.then(function(res) {
console.log(res);
})
.catch(function(error) {
console.log(error);
})
},