diff --git a/packages/varlet-ui/src/index-anchor/IndexAnchor.vue b/packages/varlet-ui/src/index-anchor/IndexAnchor.vue index 26404844951..27ca1b0e0ef 100644 --- a/packages/varlet-ui/src/index-anchor/IndexAnchor.vue +++ b/packages/varlet-ui/src/index-anchor/IndexAnchor.vue @@ -39,6 +39,7 @@ export default defineComponent({ const { active, sticky, stickyOffsetTop, zIndex } = indexBar const setOwnTop = () => { + if (!anchorEl.value) return ownTop.value = (anchorEl.value as RendererNode).$el ? (anchorEl.value as RendererNode).$el.offsetTop : (anchorEl.value as HTMLDivElement).offsetTop diff --git a/packages/varlet-ui/src/index-bar/IndexBar.vue b/packages/varlet-ui/src/index-bar/IndexBar.vue index cbfdd894c52..926c5bf1e1a 100644 --- a/packages/varlet-ui/src/index-bar/IndexBar.vue +++ b/packages/varlet-ui/src/index-bar/IndexBar.vue @@ -71,8 +71,8 @@ export default defineComponent({ }) } - const anchorClick = (anchorName: string | number) => { - props.onClick?.(anchorName) + const anchorClick = (anchorName: string | number, manualCall?: boolean) => { + if (manualCall) props.onClick?.(anchorName) if (anchorName === active.value) return const indexAnchor = indexAnchors.find(({ name }: IndexAnchorProvider) => anchorName === name.value) if (!indexAnchor) return @@ -84,7 +84,7 @@ export default defineComponent({ // expose const scrollTo = (index: number | string) => { - requestAnimationFrame(() => anchorClick(index)) + requestAnimationFrame(() => anchorClick(index, true)) } watch( diff --git a/packages/varlet-ui/src/index-bar/props.ts b/packages/varlet-ui/src/index-bar/props.ts index 42b7c0e93d7..aa87f20496b 100644 --- a/packages/varlet-ui/src/index-bar/props.ts +++ b/packages/varlet-ui/src/index-bar/props.ts @@ -14,9 +14,6 @@ export const props = { highlightColor: { type: String, }, - 'onUpdate:active': { - type: Function, - }, onClick: { type: Function, },