为什么分享出去的页面冷启动的话onLoad的options为undefined?
发布于 5 年前 作者 songxiulan 12017 次浏览 来自 问答

为什么分享出去的页面冷启动的话onLoad的options为undefined?onLaunch中有分享的参数,页面没有

1 回复

所以你需要在 app.js中将参数赋值到globalData下。

app.js

onLaunch(options) {
    this.globalData.query = options.query || {}
    if (options.referrerInfo) {
      this.globalData.query = Object.assign(this.globalData.query, options.referrerInfo.extraData)
    }
},
onShow(options) {
 this.globalData.query = options.query || {}
    if (options.referrerInfo) {
      this.globalData.query = Object.assign(this.globalData.query, options.referrerInfo.extraData)
    }
}

页面onLoad

onLoad(options) {
 this.setData({
   classId: options.classId || app.globalData.query.classId
 })
}
回到顶部