组件 / 导航 / cu-index-anchor 索引锚

cu-index-anchor

索引锚是分组顶部的字母标题,为索引列表提供跳转落点。

01 / Install

引入组件

整目录放进工程即用:easycom 按标签逐个解析,页面写哪个组件就只编译哪个,不写 import,也没有全局注册这一步;单个组件也可以显式引入(第 4 步,可选);主题层在 App.uvue 引入一次即可。

install
# 1  整目录放进工程(easycom 自动解析)
your-project/
└── uni_modules/
    └── colorui-x/

# 2  App.uvue 全局引入主题层(一次)
@import 'uni_modules/colorui-x/theme/base.css';
@import 'uni_modules/colorui-x/theme/layout.css';
@import 'uni_modules/colorui-x/theme/color.scss';  // 颜色工具类(.bg-* / .text-*)

# 3  页面里直接用,不写 import(只编译用到的组件)
<cu-index-anchor />

# 4  单个组件也可以显式引入(可选,不用 easycom 时)
import CuIndexAnchor from '@/uni_modules/colorui-x/components/cu-index-anchor/cu-index-anchor.uvue'

组件样式自包含(只依赖包内 token.scss),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。

02 / Platform

平台支持

AndroidiOSHarmonyOSWeb(H5)微信小程序支付宝小程序
√ — — √ — —

Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。

Web 列只表示已编出可运行的预览产物,非真机渲染。

其余三端没有任何实测证据,不作支持承诺。

03 / Demo

代码演示

01

默认

uvue
<cu-index-anchor />
<cu-index-anchor text="A" />
02

文案

uvue
<cu-index-anchor text="B" />
<cu-index-anchor text="热门城市" />
<cu-index-anchor text="123" />
<cu-index-anchor text="这是一段用于观察锚点是否把文字截断或换行的超长标题文案继续重复直到撑满整行" />
03

高度

uvue
<cu-index-anchor text="零高" :height="0" />
<cu-index-anchor text="默认高" />
<cu-index-anchor text="六零高" :height="60" />
<cu-index-anchor text="负高" :height="-10" />
04

字号

uvue
<cu-index-anchor text="零号" :size="0" />
<cu-index-anchor text="十号" :size="10" />
<cu-index-anchor text="默认字号" />
<cu-index-anchor text="二十号" :size="20" />
05

颜色

uvue
<cu-index-anchor text="只改文字色" color="#e54d42" />
<cu-index-anchor text="只改底色" bgColor="#0081ff" />
<cu-index-anchor text="两个都改" color="#39b54a" bgColor="#f37b1d" />
<cu-index-anchor text="两个都传空串" color="" bgColor="" />
06

吸顶

uvue
<cu-index-anchor text="粘" />
<cu-index-anchor text="底" />
07

自定义样式

uvue
<cu-index-anchor text="外距" :customStyle="blockStyle" />
<cu-index-anchor text="覆写类" customClass="custom-class" />
08

取值与事件

这一节的交互由演示页脚本驱动,效果见右侧实时预览。

04 / Props · Events · Slots

全量 API

props

参数说明类型默认值
内容与样式
text锚点标题文字,同时决定节点标识,供索引列表定位使用;为空时只留底色带与底发丝线、不显示文字String''
color标题文字颜色String'#606266'
size标题字号,px 契约值;×2 换算成 rpx(14 → 28rpx)Number14
bgColor锚点底色带颜色String'#dedede'
height锚点高度,px 契约值;×2 换算成 rpx(32 → 64rpx)Number32
交互与样式
customStyle根节点内联样式Object(): UTSJSONObject => ({})
customClass追加到根节点的类名String''
声明保留但不被消费
url不产生跳转;锚点本身不可点String''
linkType不产生跳转,同上String'navigateTo'

events

本件不派发事件。

slots

本件没有插槽。

05 / Notes

注意事项

19 · 不会吸顶 :锚点随文档流排布,滚动时不会停在顶部;本库不提供吸顶能力,需要固定的分组标题得自己用固定定位加占位盒实现。

同名锚点撞车 :两组用同一个字母时,定位只命中先出现的那组,后面的组点字母滚不过去;文字留空的锚点共用同一串标识,每组标题请保持唯一。