【Uniapp】开发环境下h5跨域问题解决方案

h5 开发环境下跨域问题处理

找到项目下 manifest.json 文件并新增

"h5": {
    "router": {
      "base": "./"
    },
    "devServer": {
      "port": 8000,
      "disableHostCheck": true,
      "proxy": {
        "/api": {
          "target" : "https://testapi.com",  // 需要跨域的域名
          "changeOrigin" : true, // 是否跨域
          "secure" : false, // 设置支持https协议的代理
          "pathRewrite" : {
            "^/api" : ""   //匹配请求路径里面有 /api 替换成 https://testapi.com
          }
        }
      }
    }
  }
posted @ 2020-09-01 11:43  [ABing]  阅读(231)  评论(0编辑  收藏  举报