Browse Source

Tooltip: avoid adding handler repeatedly

Leopoldthecoder 8 years ago
parent
commit
2057604e24
1 changed files with 8 additions and 1 deletions
  1. 8 1
      packages/tooltip/src/main.js

+ 8 - 1
packages/tooltip/src/main.js

@@ -42,6 +42,12 @@ export default {
     }
   },
 
+  data() {
+    return {
+      handlerAdded: false
+    };
+  },
+
   beforeCreate() {
     if (this.$isServer) return;
 
@@ -77,7 +83,7 @@ export default {
     if (!this.$slots.default || !this.$slots.default.length) return this.$slots.default;
 
     const vnode = getFirstComponentChild(this.$slots.default);
-    if (!vnode) return vnode;
+    if (!vnode || this.handlerAdded) return vnode;
     const data = vnode.data = vnode.data || {};
     const on = vnode.data.on = vnode.data.on || {};
     const nativeOn = vnode.data.nativeOn = vnode.data.nativeOn || {};
@@ -97,6 +103,7 @@ export default {
 
   methods: {
     addEventHandle(old, fn) {
+      this.handlerAdded = true;
       return old ? Array.isArray(old) ? old.concat(fn) : [old, fn] : fn;
     },