directives: {
preventReClick: {
inserted: function (el, binding) {
el.addEventListener('click', (e) => {
if (!el.disabled) {
el.style.pointerEvents = 'none'
setTimeout(() => {
el.style.pointerEvents = 'auto'
}, binding.value || 2000)
} else {
// disabled为true时,阻止默认的@click事件
e.preventDefault()
e.stopPropagation()
}
}, true)
}
}
},
<div @click="handelClick" v-preventReClick> 防止点</div>
<van-button @click="handelClick" v-preventReClick> 方脸点</van-button>
标签:el,防连点,vue,pointerEvents,binding,style,disabled,click
From: https://www.cnblogs.com/rzl795/p/17600145.html