Blame view

src/directives/clickoutside.js 556 Bytes
4bcfa1d5   梁灏   add file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  export default {
      bind (el, binding, vnode) {
          function documentHandler (e) {
              if (el.contains(e.target)) {
                  return false;
              }
              if (binding.expression) {
                  binding.value(e);
              }
          }
          el.__vueClickOutside__ = documentHandler;
          document.addEventListener('click', documentHandler);
      },
      update () {
  
      },
      unbind (el, binding) {
          document.removeEventListener('click', el.__vueClickOutside__);
          delete el.__vueClickOutside__;
      }
  };