簡體   English   中英

使用 Lodash 去抖動 vuejs 方法`_this2.getPoeples is not a function`

[英]Debounce a vuejs method with Lodash `_this2.getPoeples is not a function`

我嘗試使用 lodash 對一種方法進行去抖動。

我的輸入:

<el-input
    placeholder="Search poeples"
    suffix-icon="el-icon-search"
    @input="debounceGetPoeples"
    v-model="keywords">
</el-input>

我的去抖動方法:

debounceGetPoeples: debounce(() => {
        console.log('Debounce ok');
        this.getPoeples();
      }, 500),

去抖動正在工作,但是當我在視圖組件_this2.getPoeples is not a function調用另一個方法時出現錯誤

我嘗試為我的去抖做一個正常的功能,但是當我這樣做時,它被忽略了

debounceGetAnimals() {
    return debounce(() => {
      console.log('debounce ok');
      this.getPoeples();
    }, 300)
  }

我怎樣才能讓我的去抖動工作並在里面調用另一個方法?

非常感謝您的幫助

我也有過。 我現在不知道為什么箭頭符號不起作用......我想這與 lodash 使用的超時有關。

嘗試:

debounceGetAnimals() {
   var that = this;
   return debounce(() => {
      console.log('debounce ok');
      that.getPoeples();
   }, 300)
}

這個解決方案對我有用。 它對我有用的另一種方式,這里的“這個”作品是以經典方式編寫調用:

debounceGetAnimals:debounce(
   function() {
        console.log('debounce ok');
       this.getPoeples();
    }, 300)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM