vue-infinite-loading: _this.$refs.infiniteLoading.$emit is not a function

code: loadMore: function () { console.log("loadMore") getChartDetail({id: this.charts[this.activeIndex]['id'],offset:this.chartsArray[this.activeIndex].length}).then(e=>{ this.chartsArray[this.activeIndex].push(...e.books) this.$refs.infiniteLoading&&this.$refs.infiniteLoading.$emit('$InfiniteLoading:loaded'); }).catch(e => { console.log(e) }) } first time it will work,but when i continue to scroll ,next time will produce error ‘_this.$refs.infiniteLoading.$emit is not a function’

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (9 by maintainers)

Commits related to this issue

Most upvoted comments

@bruddah you can use the this.$refs.infiniteLoading.stateChanger.loaded() method to do that.

Hi everyone, v2.2.0 has been released, include this change, you can try it now, please feedback to here if you find any problem, thanks 😄

Hi everyone @tengqingya @emkman @feinimoshu753 @jkiimm @zzmm1 @xuyukuan , I think this problem cannot be fixed if this component still use $refs to send event, because it cannot ensure the ref element always be accessible. For example if this component already was destroyed after the async request complete in the on-infinite function, but the callback function still try to emit event through the $refs.infiniteLoading, this error will be thrown.

So I plan to change the way to send the loaded and complete event, it may looks like this:

...
infiniteHandler(state) {
  ajax('https://www.google.com', (data) => {
    if (data.length) {
      state.loaded();
    } else {
      state.complete();
    }
  });
}
...

What do you think? And how about the variable name state?

Best regards.

未加载完成就停止,就会出现该错误。

@zzmm1 ,感谢,但我还没找到比较好的解决办法,也许应该换一种使用方式

持续关注中…

@zzmm1 暂时还没定位到真正的原因,只是有一些推测,有待验证。不知道你是否可以在 JSFiddle 上重现你遇到的问题?