IndexBar 索引栏
uni-appH5微信小程序App
uni-app 跨端索引栏。右侧固定字母条,点击或触摸滑动字母滚动到对应分组。内部用 scroll-view 承载内容,点击字母通过 scroll-into-view 滚动到分组锚点;uni-app 端无 IndexAnchor 子组件,分组标题需自行渲染为 <view :id="'rn-index-anchor-' + idx">,吸顶降级为顶部的当前分组字母浮层(sticky 控制)。所有测量使用 uni.createSelectorQuery,跨端可用。
何时使用
通讯录、城市选择等长列表按字母分组的场景。
何时不使用
列表少于两屏或无明显分组维度时不需要索引栏。
本文档为 uni-app 端组件契约;Web 端同名组件 API 可能略有差异,请以对应包文档为准。下方手机预览实时运行 uni-app H5 演示。
9:41
IndexBar 索引栏 · uni-app H5 实时运行 新窗口打开
Props
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
indexes | string[] | "A-Z 26 字母" | 字母索引列表 |
sticky | boolean | true | 吸顶;uni-app 端降级为顶部当前分组字母浮层(Web 版作用于 IndexAnchor 组标题吸顶) |
Events
| 名称 | 载荷 | 说明 |
|---|---|---|
select | string | 点击/触摸滑动选中字母时触发,回传该字母 |
Slots
| 名称 | 说明 |
|---|---|
default | 分组内容;每组标题渲染为 <view :id="'rn-index-anchor-' + idx"> 作为滚动锚点(对应 Web 版的 IndexAnchor) |
示例
字母索引
vue
<IndexBar :indexes="['A', 'B']" style="height:320px">
<view id="rn-index-anchor-A" class="demo-head"><view class="demo-head__bar" /><text class="demo-title">A</text></view>
<Cell title="Alibaba" />
<Cell title="Ant Design" />
<view id="rn-index-anchor-B" class="demo-head"><view class="demo-head__bar" /><text class="demo-title">B</text></view>
<Cell title="ByteDance" />
<Cell title="Baidu" />
</IndexBar>关闭吸顶浮层
vue
<IndexBar :indexes="['A', 'B']" :sticky="false" style="height:240px">
<view id="rn-index-anchor-A" class="demo-head"><view class="demo-head__bar" /><text class="demo-title">A</text></view>
<Cell title="Apple" />
<view id="rn-index-anchor-B" class="demo-head"><view class="demo-head__bar" /><text class="demo-title">B</text></view>
<Cell title="ByteDance" />
</IndexBar>三组索引
vue
<IndexBar :indexes="['A', 'B', 'C']" style="height:280px">
<view id="rn-index-anchor-A" class="demo-head"><view class="demo-head__bar" /><text class="demo-title">A</text></view>
<Cell title="Alibaba" />
<view id="rn-index-anchor-B" class="demo-head"><view class="demo-head__bar" /><text class="demo-title">B</text></view>
<Cell title="Baidu" />
<view id="rn-index-anchor-C" class="demo-head"><view class="demo-head__bar" /><text class="demo-title">C</text></view>
<Cell title="Codex" />
</IndexBar>