0
点赞
收藏
分享

微信扫一扫

vue项目防抖debounce小结

罗蓁蓁 2022-03-30 阅读 68
vue.js

debounce.js在main.js中引入

import '@/utils/debounce'

import Vue from 'vue'

const on = Vue.prototype.$on
// click Event 防抖处理
Vue.prototype.$on = function (event, func) {
  let timer
  let newFunc = func
  if (event === 'click') {
    newFunc = function () {
      clearTimeout(timer)
      timer = setTimeout(function () {
        func.apply(this, arguments)
      }, 150)
    }
  }
  on.call(this, event, newFunc)
}
举报

相关推荐

0 条评论