为什么分享出去的页面冷启动的话onLoad的options为undefined?

发布于 7 年前作者 songxiulan12166 次浏览最后编辑 7 年前来自 ask

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

1 回复
weixie
weixie1 楼5 年前

所以你需要在 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
 })
}