From 709f5c65f40e8e1cc1b625b6dfe61c572ee6810d Mon Sep 17 00:00:00 2001 From: tjz <415800467@qq.com> Date: Sat, 24 Feb 2018 18:12:24 +0800 Subject: [PATCH] update --- components/_util/props-util.js | 74 +++++++++++++++++-- components/_util/vnode.js | 51 +------------ components/button/button-group.vue | 2 +- components/card/Card.vue | 3 +- components/collapse/src/Collapse.vue | 4 +- components/dropdown/dropdown.vue | 4 +- components/dropdown/src/Dropdown.vue | 4 +- components/locale-provider/LocaleReceiver.vue | 2 +- components/menu/MenuItem.vue | 3 +- components/select/index.vue | 27 ++++--- components/spin/Spin.vue | 2 +- components/tabs/index.vue | 3 +- components/tag/Tag.vue | 1 - components/tooltip/Tooltip.vue | 4 +- components/trigger/index.vue | 4 +- components/vc-menu/MenuMixin.js | 4 +- components/vc-notification/Notice.vue | 2 +- components/vc-notification/Notification.vue | 2 +- components/vc-select/Select.vue | 30 ++++---- components/vc-select/demo/optgroup.vue | 3 +- components/vc-select/util.js | 11 ++- package-lock.json | 5 ++ 22 files changed, 137 insertions(+), 108 deletions(-) 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 @@