新建preventReClick.js
export default {
install (Vue) {
// 防重复点击(指令实现)
Vue.directive('preventReClick', {
inserted (el, binding) {
el.addEventListener('click', () => {
if (!el.disabled) {
el.disabled = true
setTimeout(() => {
el.disabled = false
}, binding.value || 3000)
}
})
}
})
}
}
在main.js引入:
import preventReClick from './directive/preventReClick'
Vue.use(preventReClick)
在按钮直接使用:
<el-button @click="getData" v-preventReClick></el-button>
出处:https://www.cnblogs.com/adbg/p/11271237.html