在util.js
中添加
/**
* 拦截重复请求的自定义命令
*/
const preventReClick = Vue.directive('preventReClick', {
inserted: function (el, binding) {
el.addEventListener('click', () => {
if (!el.disabled) {
el.disabled = true;
setTimeout(() => {
el.disabled = false;
}, binding.value || 300);
}
});
}
});
export {
preventReClick
};
在vue文件中引用
import preventReClick from '@/utils/util.js';
实现方式:在按钮上添加v-preventReClick
<el-button @click="handle" v-preventReClick>提交</el-button>