自定义指令-捕获事件
//utils/enentcapuuring.vue export default { bind(el, binding, vnode) { function documentHandler(e) { if (el === e.target || el.contains(e.target)) { return false } if (binding.expression) { binding.value(e) } } el._vueClickOutside_ = documentHandler document.addEventListener('click', documentHandler, true) el.documentHandler = documentHandler }, update() {}, unbind(el, binding) { document.removeEventListener('click', el.documentHandler, true) delete el._vueClickOutside_ } } // main.js import outside from '@/utils/eventcapturing' Vue.directive('outside', outside)