Skip to content

Commit

Permalink
fix: 修改 counter render 方法
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyan-u committed Feb 29, 2024
1 parent 70c06a2 commit 9f9f564
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/guide/guide.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import TPopover, { PopoverProps } from '../popover';
import TPopup, { PopupProps } from '../popup';
import TButton, { ButtonProps } from '../button';
import config from '../config';
import { useVModel, TNode, renderTNode } from '../shared';
import { useVModel, TNode } from '../shared';
import { addClass, getWindowScroll, removeClass } from '../shared/dom';
import setStyle from '../_common/js/utils/set-style';
import guideProps from './props';
Expand Down Expand Up @@ -278,9 +278,16 @@ export default defineComponent({
total: stepsTotal.value,
current: innerCurrent.value,
};
const node =
renderTNode(getCurrentInstance(), 'counter', { params }) || ` (${innerCurrent.value + 1}/${stepsTotal.value})`;
return node;
let renderCounter: any = null;
const { counter } = props;
if (isFunction(counter)) {
renderCounter = counter(h, params);
} else if (context.slots.counter) {
renderCounter = context.slots.counter(hWithParams(params));
} else if (counter) {
renderCounter = h(counter, params);
}
return renderCounter || ` (${innerCurrent.value + 1}/${stepsTotal.value})`;
});
const isLast = computed(() => innerCurrent.value === stepsTotal.value - 1);
Expand Down
6 changes: 3 additions & 3 deletions src/shared/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export const renderTNode = (

// 同名优先处理插槽
if (instance.slots[name]) {
return instance.slots[name]?.(params);
return instance.slots[name]?.call(params);
}

if (propsNode === true && defaultNode) {
return instance.slots[name] ? instance.slots[name]?.(params) : defaultNode;
return instance.slots[name] ? instance.slots[name]?.call(params) : defaultNode;
}

if (typeof propsNode === 'function') {
Expand All @@ -48,7 +48,7 @@ export const renderTNode = (
}

const isPropsEmpty = [undefined, params, ''].includes(propsNode);
if (isPropsEmpty && instance.slots[name]) return instance.slots[name]?.(params);
if (isPropsEmpty && instance.slots[name]) return instance.slots[name]?.call(params);
return propsNode;
};

Expand Down

0 comments on commit 9f9f564

Please sign in to comment.