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 type="primary" @click="handleImportTable" v-preventReClick>确 定</el-button>