diff --git a/components/_util/props-util.js b/components/_util/props-util.js index ed40d579a..6fc4aea48 100644 --- a/components/_util/props-util.js +++ b/components/_util/props-util.js @@ -30,12 +30,28 @@ const getOptionProps = (instance) => { } const getComponentFromProp = (instance, prop) => { - const h = instance.$createElement - const temp = instance[prop] - if (temp !== undefined) { - return typeof temp === 'function' ? temp(h) : temp + if (instance.$createElement) { + const h = instance.$createElement + const temp = instance[prop] + if (temp !== undefined) { + return typeof temp === 'function' ? temp(h) : temp + } + return instance.$slots[prop] + } else { + const h = instance.context.$createElement + const temp = getPropsData(instance)[prop] + if (temp !== undefined) { + return typeof temp === 'function' ? temp(h) : temp + } + const slotsProp = [] + const componentOptions = instance.componentOptions || {}; + (componentOptions.children || []).forEach((child) => { + if (child.data && child.data.slot === prop) { + slotsProp.push(child) + } + }) + return slotsProp.length ? slotsProp : undefined } - return instance.$slots[prop] } const getPropsData = (ele) => { @@ -45,6 +61,9 @@ const getPropsData = (ele) => { } return componentOptions ? componentOptions.propsData || {} : {} } +const getValueByProp = (ele, prop) => { + return getPropsData(ele)[prop] +} const getAttrs = (ele) => { let data = ele.data @@ -61,6 +80,50 @@ const getKey = (ele) => { } return key } + +export function getEvents (child) { + let events = {} + if (child.componentOptions && child.componentOptions.listeners) { + events = child.componentOptions.listeners + } else if (child.data && child.data.on) { + events = child.data.on + } + return { ...events } +} +export function getClass (ele) { + let data = {} + if (ele.data) { + data = ele.data + } else if (ele.$vnode && ele.$vnode.data) { + data = ele.$vnode.data + } + return data.class || data.staticClass +} +export function getStyle (ele) { + let data = {} + if (ele.data) { + data = ele.data + } else if (ele.$vnode && ele.$vnode.data) { + data = ele.$vnode.data + } + return data.style || data.staticStyle +} + +export function getComponentName (opts) { + return opts && (opts.Ctor.options.name || opts.tag) +} + +export function isValidElement (ele) { + return !!ele.tag +} + +export function isEmptyElement (ele) { + return !(ele.tag || ele.text.trim() !== '') +} + +export function filterEmpty (children = []) { + return children.filter(c => c.tag || c.text.trim() !== '') +} export { hasProp, filterProps, @@ -71,5 +134,6 @@ export { getPropsData, getKey, getAttrs, + getValueByProp, } export default hasProp diff --git a/components/_util/vnode.js b/components/_util/vnode.js index 95b3de55f..c4cdb3e39 100644 --- a/components/_util/vnode.js +++ b/components/_util/vnode.js @@ -1,3 +1,4 @@ +import { filterEmpty } from './props-util' export function cloneVNode (vnode, deep) { const componentOptions = vnode.componentOptions const data = vnode.data @@ -89,54 +90,4 @@ export function cloneElement (n, nodeProps, clone) { } return node } -export function getComponentName (opts) { - return opts && (opts.Ctor.options.name || opts.tag) -} -export function isValidElement (ele) { - return !!ele.tag -} -export function isEmptyElement (ele) { - return !(ele.tag || ele.text.trim() !== '') -} - -export function getClass (ele) { - let data = {} - if (ele.data) { - data = ele.data - } else if (ele.$vnode && ele.$vnode.data) { - data = ele.$vnode.data - } - return data.class || data.staticClass -} - -export function getStyle (ele) { - let data = {} - if (ele.data) { - data = ele.data - } else if (ele.$vnode && ele.$vnode.data) { - data = ele.$vnode.data - } - return data.style || data.staticStyle -} - -export function filterEmpty (children = []) { - return children.filter(c => c.tag || c.text.trim() !== '') -} - -export function getPropsData (ele) { - return ele.componentOptions && ele.componentOptions.propsData -} -export function getValueByProp (ele, prop) { - return ele.componentOptions && ele.componentOptions.propsData && ele.componentOptions.propsData[prop] -} - -export function getEvents (child) { - let events = {} - if (child.componentOptions && child.componentOptions.listeners) { - events = child.componentOptions.listeners - } else if (child.data && child.data.on) { - events = child.data.on - } - return { ...events } -} diff --git a/components/button/button-group.vue b/components/button/button-group.vue index a69df4bf9..27f9723b4 100644 --- a/components/button/button-group.vue +++ b/components/button/button-group.vue @@ -1,5 +1,5 @@