一、新建plugins.js
import Vue from 'vue'
// 在vue上挂载一个指量 preventReClick
const preventReClick = Vue.directive('preventReClick', {
inserted: function (el, binding) {
console.log(el.disabled)
el.addEventListener('click', () => {
if (!el.disabled) {
el.disabled = true
setTimeout(() => {
el.disabled = false
}, binding.value || 3000)
//binding.value可以自行设置。如果设置了则跟着设置的时间走
//例如:v-preventReClick='500'
}
})
}
});
export { preventReClick }
二、在main.js中引入
import preventReClick from './utils/plugins.js'
三、设置button重复点击
<Button v-if="isVerificate" type="primary" @click="getCode" v-preventReClick>获取验证码</Button>