工作提效/v-clickoutside快捷指令

7/18/2024 VueFaster Demos

v-clickoutside快捷指令,点击当前DOM之外的区域触发

   directives: {
       clickoutside: {
         bind: function(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);
         },
         unbind: function(el, binding) {
           document.removeEventListener("click", el.__vueClickOutside__);
           delete el.__vueClickOutside__;
         },
       },
     },
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
最后更新于: 2024年7月24日星期三中午11点39分