新建文件

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 }

在main.js中引用

import preventReClick from './preventReClick' //防多次点击,重复提交

按钮中添加v-preventReClick

<el-button class="common-button" size="small" type="primary" @click="handleSave('form')" v-preventReClick>保 存</el-button>

Q.E.D.


Nothing really matters to me!