[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)
        })
      },
})

 

上一篇:关于vue中使用lodash的防抖用法


下一篇:2021-10-21