第一步在vue.config.js写上代理
devServer: {
hot: true,
compress: true,
disableHostCheck: true,
proxy: {
"/api": {
target: "http://xxxx:8002/Home",//你的接口地址
changeOrigin: true,//是否跨域
pathRewrite: {
"^/api": ""//接口重写,示意/api结尾的就是代理到target,即是http://xxxx:8002/Home
}
}
}
},
第二步,在axios文件外面配置baseurl
const instance3 = axios.create({
baseURL: "/api", //这里会读取vue.config外面的配置。主动重写地址。
timeout: 60000,
headers: {
"Content-Type": "application/json; charset=utf-8"
}
});
第三部,接口申请
var _this = this;
_this
.$axios3({
method: "post",
url: "gettask", //失常申请接口地址就能够了
data: { id:1 }
})
.then(function (res) {
console.log(res);
});
这就是残缺的本地代理设置
发表回复