perf: divider

pull/2682/head
tanjinzhou 2020-07-29 17:13:29 +08:00
parent 4320e8dc76
commit 72668faa25
2 changed files with 6 additions and 7 deletions

View File

@ -1,6 +1,7 @@
import { inject } from 'vue'; import { inject } from 'vue';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import { ConfigConsumerProps } from '../config-provider'; import { ConfigConsumerProps } from '../config-provider';
import { getSlot } from '../_util/props-util';
const Divider = { const Divider = {
name: 'ADivider', name: 'ADivider',
@ -16,23 +17,21 @@ const Divider = {
}; };
}, },
render() { render() {
const { prefixCls: customizePrefixCls, type, $slots, dashed, orientation = 'center' } = this; const { prefixCls: customizePrefixCls, type, dashed, orientation = 'center' } = this;
const getPrefixCls = this.configProvider.getPrefixCls; const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('divider', customizePrefixCls); const prefixCls = getPrefixCls('divider', customizePrefixCls);
const orientationPrefix = orientation.length > 0 ? '-' + orientation : orientation; const orientationPrefix = orientation.length > 0 ? '-' + orientation : orientation;
const children = getSlot(this);
const classString = { const classString = {
[prefixCls]: true, [prefixCls]: true,
[`${prefixCls}-${type}`]: true, [`${prefixCls}-${type}`]: true,
[`${prefixCls}-with-text${orientationPrefix}`]: $slots.default, [`${prefixCls}-with-text${orientationPrefix}`]: children.length,
[`${prefixCls}-dashed`]: !!dashed, [`${prefixCls}-dashed`]: !!dashed,
}; };
return ( return (
<div class={classString} role="separator"> <div class={classString} role="separator">
{$slots.default && $slots.default() && ( {!!children.length && <span class={`${prefixCls}-inner-text`}>{children}</span>}
<span class={`${prefixCls}-inner-text`}>{$slots.default()}</span>
)}
</div> </div>
); );
}, },

View File

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