【问题标题】:Debounce a vuejs method with Lodash `_this2.getPoeples is not a function`使用 Lodash `_this2.getPoeples is not a function` 去抖动 vuejs 方法
【发布时间】:2019-01-27 12:11:59
【问题描述】:

我尝试在方法上使用 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中调用另一个方法时出现错误@

我尝试为我的 debounce 做一个正常的功能,但是当我这样做时,它被忽略了

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

如何让我的 debounce 工作并在里面调用另一个方法?

非常感谢您的帮助

【问题讨论】:

    标签: javascript vuejs2


    【解决方案1】:

    我也遇到过。我现在不明白为什么箭头符号不起作用......我想这与 lodash 使用的超时有关。

    试试:

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

    这个解决方案对我有用。 它对我有用的另一种方式,这里的“this”工作是以经典方式编写调用:

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

    【讨论】:

      猜你喜欢
      • 2017-09-08
      • 1970-01-01
      • 2017-07-08
      • 2021-08-23
      • 1970-01-01
      • 2018-01-27
      • 2022-08-08
      • 2017-05-03
      • 2022-11-20
      相关资源
      最近更新 更多