防止暴力点击vue

1.添加自定义文件 preventReClick.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 ‘./store/preventReClick’ //防多次点击,重复提交

3.实现方式。在按钮上添加v-preventReClick
<el-button class=“common-button” size=“small” type=“primary” @click=“handleSave(‘form’)” v-preventReClick>保 存

上一篇:51单片机电子制作DIY-----交通灯控制器


下一篇:vue切换主题