1.vue项目/src/components/directive/clickAgain.js
import Vue from 'vue' const clickAgain = Vue.directive('clickAgain',{ // 指令的定义 bind(el, binding, vnode, oldVnode) { // 绑定this let self = vnode.context; el.onclick = function (e) { if (self._is_click) { return false; } /*执行指令绑定的事件*/ self[binding.expression]() self._is_click=true; setTimeout(()=>{ self._is_click=false; },2000) }; } }); export default clickAgain 2.在main.js 引入
import clickAgain from './components/directive/clickAgain.js'
/* 引入避免暴力双击点击*/
Vue.use(clickAgain);
3.使用
<a-button key="submit" type="primary" :loading="false" v-clickAgain="handleOk">
保存
</a-button>