美文网首页
Vue Watch 节流函数

Vue Watch 节流函数

作者: 刘佳季 | 来源:发表于2021-01-19 15:19 被阅读0次

template


<van-field

    v-model="value"

  />


watch


watch: {

    value() {

        this.fnThrottle(this.searchAction, 300)(); // 无操作,延迟300ms后执行方法

    }

}


methods


searchAction() { // 执行的函数

        console.log(this.value)

 },

fnThrottle (method, delay) {

    var timer = this.timer;

    return _=>{

        var context = this;

        var args = arguments;

        clearTimeout(timer);

        this.timer=setTimeout(_=>{

            method.apply(context,args);

        },delay);

    }

},

相关文章

网友评论

      本文标题:Vue Watch 节流函数

      本文链接:https://www.haomeiwen.com/subject/dwykzktx.html