vue2中,一种自定义指令的封装方法
export const clickoutSide = {
bind(el, binding) {
document.addEventListener(
'click',
e => hideDialogHandler(e, el, binding),
false,
);
},
unbind(el) {
document.removeEventListener('click', hideDialogHandler, false);
},
};
function hideDialogHandler(e, el, binding) {
if (el.contains(e.target)) return false;
if (binding.expression) {
binding.value(e);
}
}