关于vue.js:vue3-proxy本地代理

第一步在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);
        });


这就是残缺的本地代理设置

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理