鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ 小程序組件的生命周期中如何調(diào)用methods定義的方法?

小程序組件的生命周期中如何調(diào)用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();//這里調(diào)用方法會報(bào)錯(cuò)undefined,請問該如何調(diào)用呢?
  },
回答
編輯回答
若相惜

首先,這個(gè)在onLoad里面調(diào)用,然后你都let that = this然后在this.getList肯定是undefined啊,你要不就不要let that = this,要不就that.getList,上面的getList里面也有錯(cuò)誤,getList方法里面加上let that = this

2017年1月19日 13:15