uniapp H5页面使用uni.request时,出现跨域问题

我的 uniapp 代码是用cli 生成的,电脑没有安装HBuilderX

调用接口 出现 Provisional headers are shown 或者 Status Code: 403 Forbidden,都是跨域问题

manifest.json 加配置

"h5": {
    "devServer": {
      "port": 8888,
      "disableHostCheck": true,
      "proxy": {
        "/api": {
          "target": "http://api.xxx.com",
          "changeOrigin": true,
          "secure": false,
        }
      }
    }
  },

 以上配置,实际请求接口前默认会有 'http://aa.com/api'

也可以去掉api

"h5": {
    "devServer": {
      "port": 8888,
      "disableHostCheck": true,
      "proxy": {
        "/": {
          "target": "http://api.xxx.com",
          "changeOrigin": true,
          "secure": false
        }
      }
    }
  },

 

参见:https://blog.csdn.net/sayyy/article/details/106269732

 

 

 

 

.

posted @ 2020-11-27 11:14  James2019  阅读(4624)  评论(0编辑  收藏  举报