From 1eaec019e3b5569b377f6faa0fabf5e72cd18f24 Mon Sep 17 00:00:00 2001 From: "cinwell.li" Date: Sun, 26 Feb 2017 23:23:52 +0800 Subject: [PATCH] Tooltip: fix content slot, fixed #2999 (#3002) --- packages/tooltip/src/main.js | 6 ++++-- src/utils/vdom.js | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/tooltip/src/main.js b/packages/tooltip/src/main.js index 27d0ec21c..35f6f7b42 100644 --- a/packages/tooltip/src/main.js +++ b/packages/tooltip/src/main.js @@ -1,5 +1,6 @@ import Popper from 'element-ui/src/utils/vue-popper'; import debounce from 'throttle-debounce/debounce'; +import { getFirstComponentChild } from 'element-ui/src/utils/vdom'; import Vue from 'vue'; export default { @@ -65,9 +66,10 @@ export default { ); - if (!this.$slots.default) return this.$slots.default; + if (!this.$slots.default || !this.$slots.default.length) return this.$slots.default; - const vnode = this.$slots.default[0]; + const vnode = getFirstComponentChild(this.$slots.default); + if (!vnode) return vnode; const data = vnode.data = vnode.data || {}; const on = vnode.data.on = vnode.data.on || {}; diff --git a/src/utils/vdom.js b/src/utils/vdom.js index f31646d25..f4df71620 100644 --- a/src/utils/vdom.js +++ b/src/utils/vdom.js @@ -1,6 +1,9 @@ import Vue from 'vue'; export function isVNode(node) { - if (!node || typeof node !== 'object') return false; - return Vue.util.hasOwn(node, 'tag') && Vue.util.hasOwn(node, 'componentOptions'); + return typeof node === 'object' && Vue.util.hasOwn(node, 'componentOptions'); +}; + +export function getFirstComponentChild(children) { + return children && children.filter(c => c && c.tag)[0]; };