Preview Updated 2026-05-10

Anchor

Sidebar that lists page anchors explicitly, highlights the section in view as you scroll, and smooth-scrolls on click.

Basic usage

items is the anchor list; each entry is { href, label }. href looks like #section-id and corresponds to a <h2 id="section-id"> on the page. One level of children nesting is supported.

概述

这是概述部分的第 1 段示例文本。

这是概述部分的第 2 段示例文本。

这是概述部分的第 3 段示例文本。

这是概述部分的第 4 段示例文本。

基础用法

这是基础用法部分的第 1 段示例文本。

这是基础用法部分的第 2 段示例文本。

这是基础用法部分的第 3 段示例文本。

这是基础用法部分的第 4 段示例文本。

API

这是 API 部分的第 1 段示例文本。

这是 API 部分的第 2 段示例文本。

这是 API 部分的第 3 段示例文本。

这是 API 部分的第 4 段示例文本。

<CfAnchor :items="items" :offset-top="0" />
<CfAnchor items={items} offsetTop={0} />

API

PropTypeDefaultDescription
itemsAnchorItem[]Anchor list
offsetTopnumber0Top offset (in pixels) used for highlight detection and scroll-to
boundsnumber5An element is considered in view when its top distance ≤ bounds + offsetTop; smaller is stricter
targetstringScroll container selector; omit to listen on window

AnchorItem

FieldTypeDescription
hrefstringAnchor hash, e.g. #install
labelstringDisplay text
childrenAnchorItem[]Child anchors

Events: onChange(href) — fires when the highlighted anchor changes.

反馈与讨论

Anchor · Discussion

0
0 / 600
一键发送
正在加载评论...