第一步在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文件中配置baseurlconstinstance3=axios.create({baseURL:"/api",//这里会读取vue.config配置中的内容,自动重写address.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);});这是完整的本地代理设置
