IndexBar 索引栏
WebH5
索引栏。右侧固定字母条,点击或触摸滑动字母滚动到对应分组,配合 IndexAnchor 渲染(吸顶)组标题。
何时使用
通讯录、城市选择等长列表按字母分组的场景。
何时不使用
列表少于两屏或无明显分组维度时不需要索引栏。
Props
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
indexes | string[] | "A-Z 26 字母" | 字母索引列表 |
sticky | boolean | true | 组标题吸顶(作用于内部 IndexAnchor) |
Events
| 名称 | 载荷 | 说明 |
|---|---|---|
select | string | 点击/触摸滑动选中字母时触发,回传该字母 |
Slots
| 名称 | 说明 |
|---|---|
default | 分组内容;每组用 IndexAnchor 标记组标题 |
示例
城市选择(按字母导航)
示例加载中…
<div style="height:300px;border:1px solid var(--rn-color-border);border-radius:8px;overflow:hidden">
<IndexBar :indexes="['A', 'B', 'G', 'H', 'S']">
<IndexAnchor index="A" />
<Cell title="鞍山" />
<Cell title="安庆" />
<IndexAnchor index="B" />
<Cell title="北京" />
<Cell title="保定" />
<IndexAnchor index="G" />
<Cell title="广州" />
<Cell title="贵阳" />
<IndexAnchor index="H" />
<Cell title="杭州" />
<Cell title="合肥" />
<IndexAnchor index="S" />
<Cell title="上海" />
<Cell title="深圳" />
</IndexBar>
</div>全字母索引 A-Z
示例加载中…
<div style="height:300px;border:1px solid var(--rn-color-border);border-radius:8px;overflow:hidden">
<IndexBar :indexes="['A','B','C','D','E','F','G','H']">
<IndexAnchor index="A" />
<Cell title="苹果" />
<IndexAnchor index="B" />
<Cell title="菠萝" />
<IndexAnchor index="C" />
<Cell title="草莓" />
<IndexAnchor index="D" />
<Cell title="冬瓜" />
<IndexAnchor index="E" />
<Cell title="鹅蛋" />
<IndexAnchor index="F" />
<Cell title="番茄" />
<IndexAnchor index="G" />
<Cell title="柑橘" />
<IndexAnchor index="H" />
<Cell title="哈密瓜" />
</IndexBar>
</div>事件监听
示例加载中…
<div style="height:240px;border:1px solid var(--rn-color-border);border-radius:8px;overflow:hidden">
<IndexBar :indexes="['A','B','C','D']" @select="console.log('选中索引:', $event)">
<IndexAnchor index="A" />
<Cell title="Apple" />
<IndexAnchor index="B" />
<Cell title="Banana" />
<IndexAnchor index="C" />
<Cell title="Cherry" />
<IndexAnchor index="D" />
<Cell title="Durian" />
</IndexBar>
</div>不吸顶模式
示例加载中…
<div style="height:240px;border:1px solid var(--rn-color-border);border-radius:8px;overflow:hidden">
<IndexBar :indexes="['A','B','C']" :sticky="false">
<IndexAnchor index="A" />
<Cell title="Item A-1" />
<Cell title="Item A-2" />
<IndexAnchor index="B" />
<Cell title="Item B-1" />
<IndexAnchor index="C" />
<Cell title="Item C-1" />
<Cell title="Item C-2" />
</IndexBar>
</div>Playground
加载中…
跨端版本
该组件同时提供 uni-app / uni-app X 实现(H5 / 微信小程序 / App),API 可能略有差异,见 uni-app 端 IndexBar 文档(含手机预览)。