1.添加一个js文件
直接复制就可以
import Vue from 'vue'
const preventReClick = Vue.directive('preventReClick', {
inserted: function (el, binding) {
el.addEventListener('click', () => {
if (!el.disabled) {
el.disabled = true
setTimeout(() => {
el.disabled = false
}, binding.value || 3000)
}
})
}
});
export { preventReClick }
2.在main.js 中引用方法
`import preventReClick from './js/preventReClick'
3.在需要控制的 按钮上 添加v-preventReClick就行
demo:
<input type="button" style="border: none;" class="sent"
@click="sendcode" v-preventReClick
:disabled="disabled" v-model="btntxt" />