onShareTimeline打印this是undefined?

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

场景:微信小程序安卓手机分享朋友圈,this.data.title 取不到值,直接报错。

  //分享朋友圈
  onShareTimeline() {
    console.log('分享朋友圈',this) // 分享朋友圈
    return {
      title: this.data.title // Cannot read property 'data' of undefined
    }
  }
3 回复
qiang04
qiang041 楼5 年前
  onShareTimeline: function (res) {
    console.log('分享朋友圈',this) // 分享朋友圈
    return {
      title: this.data.title // Cannot read property 'data' of undefined
    }
  }
itao
itao2 楼5 年前

daimin
daimin3 楼5 年前

let _this =this;return { _this.data.title}