From dd68c0d314199d8073cc3126299a4f46e8d98cf5 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Mon, 29 Jun 2020 22:22:25 +0800 Subject: [PATCH] fix: vc-select --- components/_util/props-util.js | 23 +++++++++++++++++------ examples/App.vue | 2 +- examples/index.js | 6 ++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/components/_util/props-util.js b/components/_util/props-util.js index 81158a924..efcc81c5d 100644 --- a/components/_util/props-util.js +++ b/components/_util/props-util.js @@ -139,7 +139,7 @@ const getComponent = (instance, prop = 'default', options = instance, execute = } } else if (isVNode(instance)) { const temp = instance.props && instance.props[prop]; - if (temp !== undefined) { + if (temp !== undefined && temp !== null) { return typeof temp === 'function' && execute ? temp(options) : temp; } else if (instance.children && instance.children[prop]) { let com = instance.children[prop]; @@ -305,7 +305,11 @@ export function isFragment(c) { } export function isEmptyElement(c) { - return c.type === Comment || (c.type === Text && c.children.trim() === ''); + return ( + c.type === Comment || + (c.type === Fragment && c.children.length === 0) || + (c.type === Text && c.children.trim() === '') + ); } export function isStringElement(c) { @@ -313,10 +317,17 @@ export function isStringElement(c) { } export function filterEmpty(children = []) { - if (isFragment(children)) { - return children[0].children.filter(c => !isEmptyElement(c)); - } - return children.filter(c => !isEmptyElement(c)); + const res = []; + children.forEach(child => { + if (Array.isArray(child)) { + res.push(...child); + } else if (child.type === Fragment) { + res.push(...child.children); + } else { + res.push(child); + } + }); + return res.filter(c => !isEmptyElement(c)); } const initDefaultProps = (propTypes, defaultProps) => { Object.keys(defaultProps).forEach(k => { diff --git a/examples/App.vue b/examples/App.vue index dc52a4f82..1ed1eccbf 100644 --- a/examples/App.vue +++ b/examples/App.vue @@ -4,7 +4,7 @@