fix: vc-select

pull/2510/head
tangjinzhou 2020-06-29 22:22:25 +08:00
parent 106b82ca67
commit dd68c0d314
3 changed files with 24 additions and 7 deletions

View File

@ -139,7 +139,7 @@ const getComponent = (instance, prop = 'default', options = instance, execute =
} }
} else if (isVNode(instance)) { } else if (isVNode(instance)) {
const temp = instance.props && instance.props[prop]; const temp = instance.props && instance.props[prop];
if (temp !== undefined) { if (temp !== undefined && temp !== null) {
return typeof temp === 'function' && execute ? temp(options) : temp; return typeof temp === 'function' && execute ? temp(options) : temp;
} else if (instance.children && instance.children[prop]) { } else if (instance.children && instance.children[prop]) {
let com = instance.children[prop]; let com = instance.children[prop];
@ -305,7 +305,11 @@ export function isFragment(c) {
} }
export function isEmptyElement(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) { export function isStringElement(c) {
@ -313,10 +317,17 @@ export function isStringElement(c) {
} }
export function filterEmpty(children = []) { export function filterEmpty(children = []) {
if (isFragment(children)) { const res = [];
return children[0].children.filter(c => !isEmptyElement(c)); children.forEach(child => {
} if (Array.isArray(child)) {
return children.filter(c => !isEmptyElement(c)); 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) => { const initDefaultProps = (propTypes, defaultProps) => {
Object.keys(defaultProps).forEach(k => { Object.keys(defaultProps).forEach(k => {

View File

@ -4,7 +4,7 @@
</div> </div>
</template> </template>
<script> <script>
import demo from '../antdv-demo/docs/input-number/demo/index'; import demo from '../antdv-demo/docs/select/demo/tags';
export default { export default {
components: { components: {

View File

@ -2,6 +2,9 @@ import '@babel/polyfill';
import { createApp } from 'vue'; import { createApp } from 'vue';
import App from './App.vue'; import App from './App.vue';
import { import {
Radio,
Spin,
Select,
Input, Input,
InputNumber, InputNumber,
Rate, Rate,
@ -32,6 +35,8 @@ app
.component('api', { ...basic }) .component('api', { ...basic })
.component('CN', { ...basic }) .component('CN', { ...basic })
.component('US', { ...basic }) .component('US', { ...basic })
.use(Select)
.use(Spin)
.use(Upload) .use(Upload)
.use(Button) .use(Button)
.use(Icon) .use(Icon)
@ -42,5 +47,6 @@ app
.use(Tooltip) .use(Tooltip)
.use(Col) .use(Col)
.use(Row) .use(Row)
.use(Radio)
.use(InputNumber) .use(InputNumber)
.mount('#app'); .mount('#app');