配置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

 

相关文章:

  • 2021-06-25
  • 2021-11-02
  • 2021-11-29
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
猜你喜欢
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2022-01-12
  • 2021-08-18
  • 2021-08-31
相关资源
相似解决方案