在util.js
中添加
/**
* 攔截重復(fù)請(qǐng)求的自定義命令
*/
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';
實(shí)現(xiàn)方式:在按鈕上添加v-preventReClick
<el-button @click="handle" v-preventReClick>提交</el-button>