这里是按钮的节流,就没用防抖
const setVueClickGlobalThrottle = Vue => {
// 节流
const on = Vue.prototype.$on
Vue.prototype.$on = function (event, func) {
console.info('全局拦截 click $on事件 event', event)
let previous = 0
let newFunc = func
if (event === 'click') {
console.info('全局拦截 click 事件 setVueClickGlobalThrottle')
newFunc = function () {
const now = new Date().getTime()
if (previous + 1000 <= now) {
func.apply(this, arguments)
previous = now
}
}
}
on.call(this, event, newFunc)
}
}
export default setVueClickGlobalThrottle
main.js 里面加载
import setVueClickGlobalThrottle from '@/libs/common/setVueClickGlobalThrottle.js'
setVueClickGlobalThrottle(Vue) // 将所有click 进行节流处理