zoukankan      html  css  js  c++  java
  • vue使用代理实现开发阶段跨域

    在config/index.js找到 proxyTable对象,添加键值对即可。

    "/api":{

      target:"http://192.168.1.1",

      changeOrighn:true,

      pathRewrite:{

        "^/api":" "

      }

    }

    倘若加上了这对键值对,意思就是以后的请求路径中存在 /api ,就是将 /api 隐式替换成 target+pathRewrite["/api"]

    可能说了这样说,大家还是有点不明白,那就举一个例子:

      在使用vue时,请求地址,均为 localhost开头,若需要请求到 192.168.1.115/dataForYou 接口的数据,那么就存在跨域限制,那么就可以在配置文件中加上

    "/api":{

      target:"http://192.168.1.115",

      changeOrighn:true,

      pathRewrite:{

        "^/api":" "

      }

    },然后直接请求 /api/dataForYou,即可获得数据,并且其中 /api 可以保存为全局变量。

    那么里面的pathRewrite到底有什么作用呢?我想应该是为了方便接口,

    假如,有大量接口 {192.168.1.15/a/1-100}{100}, {198.168.1.15/b/1-100}{100};那么定义target为192.168.1.15,在pathRewrite中定义

    Just For You
  • 相关阅读:
    DRF分页器
    DRF版本控制
    crrm复习
    python面试题网络编程和数据库
    python基础面试题
    前端格式
    数据库基本命令
    数据库管理系统
    线程协程和进程
    IPC通信
  • 原文地址:https://www.cnblogs.com/ZT0219/p/8664811.html
Copyright © 2011-2022 走看看