微信小程序不同环境配置不同接口地址

uniapp:
uni.getAccountInfoSync() 可以获取到当前在哪个环境,下面是文档地址
https://uniapp.dcloud.net.cn/api/other/getAccountInfoSync.html#getaccountinfosync


const {
    
     miniProgram: {
    
     envVersion } } = uni.getAccountInfoSync();
const apiUrl = {
    
    
  develop: "dev接口地址",
  trial: "dev接口地址,这个随便配,看测试需要",
  release: "正式环境地址"
}[envVersion];

uni.request({
    
    
      method, 
      url: apiUrl,// 直接使用上面定义的apiUrl 变量即可
      header: {
    
    
      },
      data: {
    
    
      },
      success(res: any) {
    
    
      },
      fail(err) {
    
    
      }
    })

猜你喜欢

转载自blog.csdn.net/be_strong_web/article/details/129277965