uni-app 跨域问题解决

uni-app 跨域问题解决

wangxl@20200708

一、uni-app 中 manifest.json文件修改,增加h5节点

uni-app 跨域问题解决_第1张图片

 

"h5" : {

        "devServer" : {

            "https" : false,

            "port" : 8080,

"proxy" : {

"/apis" : {

"target" : "http://api.heclouds.com",

"changeOrigin" : true,

"secure" : false,

"pathRewrite" : {

"^/apis" : ""

}

}

}

 

        }

}

 

二、应用调用修改 https://api.heclouds.com 改为/apis

uni.request({

   //   url: "https://api.heclouds.com/devices",

  url: "/apis/devices",

      header: {

        "api-key": "********"

      },

      data: {

 

      },

      success(res) {

        console.log(res)

       

      },

      fail(res) {

        console.log("请求失败")

      }

    })

你可能感兴趣的:(uni-app)