binmengxue

这个问题我找了好久没有找到解决方法,然后自己想了一个办法

1.首页需要你在远程服务器添加一个JSON文件,里面只添加了debug判断是线上还是测试环境

{ "debug":true}

2.在app.js中添加globalData添加全局isDebug,host

globalData: {
      host: \'XXX\',
      isDebug:false,
  }

3.然后index.js中添加如下代码,index.js是我服装的所有接口文件,promise解决异步问题

 

 index.js中代码

 

 

let DEBUG = false;
let baseUrl = \'\'
var promise =new Promise((resolve, reject) => {
  wx.request({
    url: \'https://www.zhiyunyi.net//host.json\',//json数据地址
    headers: {
      \'Content-Type\': \'application/json\'
    },
    success: function (res) {
      console.log(res)
      let obj=res.data;
      getApp().globalData.isDebug=obj.debug
      if(obj.debug){
        getApp().globalData.host=\'https://courtdev.zhiyunyi.net\'//这是测试环境的host
        resolve(getApp().globalData.host); // 这里是关键
      }else{
        getApp().globalData.host=\'https://court.zhiyunyi.net\'//这是线上环境的host
        resolve(getApp().globalData.host); // 这里是关键
      }
    }
  })
})
promise.then(res=>{
 baseUrl=res
})

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-07-16
  • 2022-01-02
  • 2021-07-25
猜你喜欢
  • 2021-12-07
  • 2021-07-28
  • 2022-12-23
  • 2021-12-21
  • 2021-05-07
  • 2021-12-19
  • 2022-03-01
相关资源
相似解决方案