默认
<cu-index-anchor /> <cu-index-anchor text="A" />
索引锚是分组顶部的字母标题,为索引列表提供跳转落点。
整目录放进工程即用:easycom 按标签逐个解析,页面写哪个组件就只编译哪个,不写 import,也没有全局注册这一步;单个组件也可以显式引入(第 4 步,可选);主题层在 App.uvue 引入一次即可。
# 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),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。
| Android | iOS | HarmonyOS | Web(H5) | 微信小程序 | 支付宝小程序 |
|---|---|---|---|---|---|
| √ | — | — | √ | — | — |
Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。
Web 列只表示已编出可运行的预览产物,非真机渲染。
其余三端没有任何实测证据,不作支持承诺。
<cu-index-anchor /> <cu-index-anchor text="A" />
<cu-index-anchor text="B" /> <cu-index-anchor text="热门城市" /> <cu-index-anchor text="123" /> <cu-index-anchor text="这是一段用于观察锚点是否把文字截断或换行的超长标题文案继续重复直到撑满整行" />
<cu-index-anchor text="零高" :height="0" /> <cu-index-anchor text="默认高" /> <cu-index-anchor text="六零高" :height="60" /> <cu-index-anchor text="负高" :height="-10" />
<cu-index-anchor text="零号" :size="0" /> <cu-index-anchor text="十号" :size="10" /> <cu-index-anchor text="默认字号" /> <cu-index-anchor text="二十号" :size="20" />
<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="" />
<cu-index-anchor text="粘" /> <cu-index-anchor text="底" />
<cu-index-anchor text="外距" :customStyle="blockStyle" /> <cu-index-anchor text="覆写类" customClass="custom-class" />
这一节的交互由演示页脚本驱动,效果见右侧实时预览。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| 内容与样式 | |||
| text | 锚点标题文字,同时决定节点标识,供索引列表定位使用;为空时只留底色带与底发丝线、不显示文字 | String | '' |
| color | 标题文字颜色 | String | '#606266' |
| size | 标题字号,px 契约值;×2 换算成 rpx(14 → 28rpx) | Number | 14 |
| bgColor | 锚点底色带颜色 | String | '#dedede' |
| height | 锚点高度,px 契约值;×2 换算成 rpx(32 → 64rpx) | Number | 32 |
| 交互与样式 | |||
| customStyle | 根节点内联样式 | Object | (): UTSJSONObject => ({}) |
| customClass | 追加到根节点的类名 | String | '' |
| 声明保留但不被消费 | |||
| url | 不产生跳转;锚点本身不可点 | String | '' |
| linkType | 不产生跳转,同上 | String | 'navigateTo' |
本件不派发事件。
本件没有插槽。
19 · 不会吸顶 :锚点随文档流排布,滚动时不会停在顶部;本库不提供吸顶能力,需要固定的分组标题得自己用固定定位加占位盒实现。
同名锚点撞车 :两组用同一个字母时,定位只命中先出现的那组,后面的组点字母滚不过去;文字留空的锚点共用同一串标识,每组标题请保持唯一。