其他分享
首页 > 其他分享> > [vue]防抖(debounce) 和 节流(throttling)

[vue]防抖(debounce) 和 节流(throttling)

作者:互联网

debounce.js
import Vue from "vue"
Vue.directive("debounce", {
    inserted: function (el, binding) {
        let timer
        el.addEventListener('click', () => {
          if (timer) {
            clearTimeout(timer)
          }
          timer = setTimeout(() => {
            binding.value()
          }, 1000)
        })
      },
})

 

标签:el,防抖,vue,debounce,binding,timer,Vue
来源: https://www.cnblogs.com/lv77/p/15556391.html