uni-app跨域解决

配置uni-app 中 manifest.json->h5->devServer
manifest.json

/* h5特有相关 */
"h5" : {
  "devServer" : {
  "port" : 8080, //端口号
  "disableHostCheck" : true,
  "proxy" : {
    "/api" : {
    "target" : "http://192.168.4.85:8089", //目标接口域名
    "changeOrigin" : true, //是否跨域
    "secure" : false // 设置支持https协议的代理
      }
    }
  }
}

// 接口路径
const rootPath = "/api/";

const post=function(url,data,callBack){
  var ajaxData={
    url: rootPath+url,
    method: "POST",
    data:data,
    dataType:'json',
    header:{
      'content-type':'application/x-www-form-urlencoded'
    },
    success: callBack
  }
  ajaxData = ajaxData;
  uni.request(ajaxData)
}

1、需要配置相关的配置文件。

2、修改请求的接口。

这样,我们就实现了在 uniapp 中解决了跨域的问题。方便了我们的接口调用。

最后,感谢前人的分享:

  https://blog.csdn.net/csdn_xng/article/details/88680309

       https://www.cnblogs.com/PYiP/p/11244134.html

原文地址:https://www.cnblogs.com/liner730/p/11338242.html