每次都会调用去抖功能

我在keyUp上调用searchkeyword函数。我想在快速键入新字母时取消/ clearTimeout $ emit,以便只调用几次$ emit。但是控制台会在每次搜索关键字调用时被调用/反跳。


  methods: {

    searchKeyword : function() {

      var scope = this;

      (this.debounce(function(){

        scope.$emit("search-keyword", scope.keyword);

        console.log("Called");

      },350))();

    },

    debounce: function (func, delay) {

        var timeout;

        return function() {

          const context = this;

          const args = arguments;

          clearTimeout(timeout);

          timeout = setTimeout(() => func.apply(context, args), delay);

        }

      }

    }


缥缈止盈
浏览 154回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript