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

1次阅读

共计 549 个字符,预计需要花费 2 分钟才能阅读完成。

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


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

正文完
 0