Browse Source

fix: vc-select

pull/2510/head
tangjinzhou 4 years ago
parent
commit
dd68c0d314
  1. 23
      components/_util/props-util.js
  2. 2
      examples/App.vue
  3. 6
      examples/index.js

23
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 => {

2
examples/App.vue

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

6
examples/index.js

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

Loading…
Cancel
Save