小程序组件的生命周期中如何调用methods定义的方法?

以下是小程序组件代码

methods: {
    getList: function () {
      util.get(`${config.service.host}/web/news/list_with_pub_info?channelId=${config.channelId}&page=${that.data.page}&size=${that.data.size}`, function (res) {
        that.setData({
          newsList: res.data.content,
          totalPages: res.data.totalPages
        })
      }, function (e) {
        console.log(JSON.stringify(e));
      });
     },
  },
  ready: function (options) {
    let that = this;
    this.getList();//这里调用方法会报错undefined,请问该如何调用呢?
  },
阅读 5.4k
1 个回答

首先,这个在onLoad里面调用,然后你都let that = this然后在this.getList肯定是undefined啊,你要不就不要let that = this,要不就that.getList,上面的getList里面也有错误,getList方法里面加上let that = this

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题