【问题标题】:Debounce an async method?反跳异步方法?
【发布时间】:2020-10-29 01:34:13
【问题描述】:

我有:

async search() {

如何实现 lo dash 的告发?我试过了:

async search: _.debounce(function () {

但没有运气。

【问题讨论】:

  • 什么是'await'在'function'前面?

标签: vue.js vuejs2


【解决方案1】:

试试这个:

<input type="text" @keypress="searchDebounce" />
methods: {
    async search() {
        // get search result
    },
    searchDebounce: _.debounce(async function() {
        await this.search();
        // or you can move everything from search() to here, and delete this.search()
    }, 1000)
}

even better:

data() {
  return {
    searchDebounce: null
  };
},
created() {
  this.searchDebounce = debounce(this.search, 1000);
}

【讨论】:

    猜你喜欢
    • 2019-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多