1、添加自定义JS文件:submitCheck.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 './common/submitCheck' //防多次点击,重复提交
3、使用:v-preventReClick
<button type="submit" class="btn btn-primary" @click="$emit('ok')" v-preventReClick>{{confirmBtLable}}</button>
评论区