Browse Source

fix(BasicTree): not inherit slot and not show icon slot. close #1902

pull/3181/head
invalid w 3 years ago
parent
commit
a0b2a9e949
  1. 18
      src/components/Tree/src/BasicTree.vue
  2. 2
      src/components/Tree/src/TreeIcon.ts

18
src/components/Tree/src/BasicTree.vue

@ -393,16 +393,26 @@
) : (
title
);
const iconDom = icon ? (
<TreeIcon icon={icon} />
) : slots.icon ? (
<span class="mr-1">{getSlot(slots, 'icon')}</span>
) : null;
item[titleField] = (
<span
class={`${bem('title')} pl-2`}
onClick={handleClickNode.bind(null, item[keyField], item[childrenField])}
>
{slots?.title ? (
getSlot(slots, 'title', item)
<>
{iconDom}
{getSlot(slots, 'title', item)}
</>
) : (
<>
{icon && <TreeIcon icon={icon} />}
{iconDom}
{titleDom}
<span class={bem('actions')}>{renderAction(item)}</span>
</>
@ -444,7 +454,9 @@
tip="加载中..."
>
<ScrollContainer style={scrollStyle} v-show={!unref(getNotFound)}>
<Tree {...unref(getBindValues)} showIcon={false} treeData={treeData.value} />
<Tree {...unref(getBindValues)} showIcon={false} treeData={treeData.value}>
{extendSlots(slots, ['title'])}
</Tree>
</ScrollContainer>
<Empty
v-show={unref(getNotFound)}

2
src/components/Tree/src/TreeIcon.ts

@ -3,7 +3,7 @@ import { h } from 'vue';
import { isString } from 'lodash-es';
import Icon from '@/components/Icon/Icon.vue';
export const TreeIcon = ({ icon }: { icon: VNode | string }) => {
export const TreeIcon = ({ icon }: { icon: VNode | string | undefined }) => {
if (!icon) return null;
if (isString(icon)) {
return h(Icon, { icon, class: 'mr-1' });

Loading…
Cancel
Save