收藏
回答

app.js如何把下面的两个onLaunch:function()整合到一起不报错?

App({
  onLaunchfunction () {
      if (!wx.cloud) {
        console.error('请使用 2.2.3 或以上的基础库以使用云能力')
      } else {
        wx.cloud.init({
          // env 参数说明:
          //   env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源
          //   此处请填入环境 ID, 环境 ID 可打开云控制台查看
          //   如不填则使用默认环境(第一个创建的环境)
          // env: 'my-env-id',
          traceUsertrue,
        })
      }
    this.globalData = {}
  },
  onLaunch:function (options{
    if (options.scene == 1007 || options.scene == 1008) {
      this.globalData.share = true
    } else {
      this.globalData.share = false
    };

    wx.getSystemInfo({
      success(res) => {
        this.globalData.height = res.statusBarHeight
      }
    })
  },
  globalData: {
    sharefalse,  // 分享默认为false
    height0,
  },
  
})
回答关注问题邀请回答
收藏

1 个回答

  • 乐豆信息
    乐豆信息
    2020-08-21
    App({
      globalData: {
        share: false,  // 分享默认为false
        height: 0,
      },
      onLaunch(options) {
        this.initCloud();
        this.initShare(options);
      },
      initCloud: function () {
          if (!wx.cloud) {
            console.error('请使用 2.2.3 或以上的基础库以使用云能力')
          } else {
            wx.cloud.init({
              // env 参数说明:
              //   env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源
              //   此处请填入环境 ID, 环境 ID 可打开云控制台查看
              //   如不填则使用默认环境(第一个创建的环境)
              // env: 'my-env-id',
              traceUser: true,
            })
          }
      },
      initShare:function (options) {
        if (options.scene == 1007 || options.scene == 1008) {
          this.globalData.share = true
        } else {
          this.globalData.share = false
        };
    
    
        wx.getSystemInfo({
          success: (res) => {
            this.globalData.height = res.statusBarHeight
          }
        })
      }
    })
    
    2020-08-21
    有用 1
    回复
登录 后发表内容
问题标签