From bf3e4f32c382aaac07041120a2cd6bbb2033f692 Mon Sep 17 00:00:00 2001 From: AC-0308 Date: Mon, 15 Dec 2025 18:40:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(OAnchor):=20=E2=9C=A8=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0observeHref=E5=8F=82=E6=95=B0=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E7=9B=91=E5=90=AC=E5=85=83=E7=B4=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../opendesign/src/anchor/OAnchorItem.vue | 20 ++++++++++--------- packages/opendesign/src/anchor/types.ts | 7 +++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/opendesign/src/anchor/OAnchorItem.vue b/packages/opendesign/src/anchor/OAnchorItem.vue index c069fb20..2f5eb44c 100644 --- a/packages/opendesign/src/anchor/OAnchorItem.vue +++ b/packages/opendesign/src/anchor/OAnchorItem.vue @@ -21,22 +21,24 @@ const emits = defineEmits<{ const anchorInjection = inject(anchorInjectKey, null); const anchorItemInjection = inject(anchorItemInjectKey, null); +const _observeHref = computed(() => props.observeHref || props.href) + const isActive = computed(() => { - return props.href === anchorInjection?.activeLink.value; + return _observeHref.value === anchorInjection?.activeLink.value; }); const addItem = () => { - if (!props.href) { + if (!_observeHref.value) { return; } - anchorInjection?.addLink(props.href); + anchorInjection?.addLink(_observeHref.value); }; const removeItem = () => { - if (!props.href) { + if (!_observeHref.value) { return; } - anchorInjection?.removeLink(props.href); + anchorInjection?.removeLink(_observeHref.value); }; const onClick = (event: MouseEvent) => { @@ -60,15 +62,15 @@ const onClick = (event: MouseEvent) => { */ anchorInjection?.onItemClick({ event: event, - link: props.href, + link: _observeHref.value, }); - if (props.href) { - anchorInjection?.scrollIntoView(props.href); + if (_observeHref.value) { + anchorInjection?.scrollIntoView(_observeHref.value); } }; watch( - () => props.href, + () => _observeHref.value, (newVal, oldVal) => { nextTick(() => { if (oldVal) { diff --git a/packages/opendesign/src/anchor/types.ts b/packages/opendesign/src/anchor/types.ts index 862fb67f..4c16b5ab 100644 --- a/packages/opendesign/src/anchor/types.ts +++ b/packages/opendesign/src/anchor/types.ts @@ -68,6 +68,13 @@ export const anchorItemProps = { type: String, required: true, }, + /** + * @zh-CN 锚点监听的目标元素(带#前缀),不传时监听href + * @en-US Target element for anchor observe (with # prefix),Use href prop by default + */ + observeHref: { + type: String, + }, /** * @zh-CN 锚点跳转方式 * @en-US Anchor navigation method -- Gitee From 8e7273d09f5a05d223f239c31f2b71ed94221c63 Mon Sep 17 00:00:00 2001 From: AC-0308 Date: Mon, 15 Dec 2025 19:28:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?doc(OAnchor):=20=F0=9F=93=9D=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0observeHref=E7=9B=B8=E5=85=B3=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../opendesign/src/anchor/__docs__/__case__/AnchorUsage.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/opendesign/src/anchor/__docs__/__case__/AnchorUsage.vue b/packages/opendesign/src/anchor/__docs__/__case__/AnchorUsage.vue index ac7addf2..83e99cd9 100644 --- a/packages/opendesign/src/anchor/__docs__/__case__/AnchorUsage.vue +++ b/packages/opendesign/src/anchor/__docs__/__case__/AnchorUsage.vue @@ -126,14 +126,14 @@ const _oTemplate: DocDemoTemplate = (props) => { - + - + -- Gitee