mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-12 01:58:58 +08:00
89 lines
1.7 KiB
Markdown
89 lines
1.7 KiB
Markdown
# IndexBar 索引栏
|
|
|
|
### 引入
|
|
|
|
``` javascript
|
|
import { IndexBar, IndexAnchor } from 'vant';
|
|
|
|
Vue.use(IndexBar).use(IndexAnchor);
|
|
```
|
|
|
|
## 代码演示
|
|
|
|
### 基础用法
|
|
|
|
点击索引栏时,会自动跳转到对应的`IndexAnchor`锚点位置
|
|
|
|
```html
|
|
<van-index-bar>
|
|
<van-index-anchor index="A" />
|
|
<van-cell title="文本" />
|
|
<van-cell title="文本" />
|
|
<van-cell title="文本" />
|
|
|
|
<van-index-anchor index="B" />
|
|
<van-cell title="文本" />
|
|
<van-cell title="文本" />
|
|
<van-cell title="文本" />
|
|
|
|
...
|
|
</van-index-bar>
|
|
```
|
|
|
|
### 自定义索引列表
|
|
|
|
可以通过`index-list`属性自定义展示的索引字符列表,
|
|
|
|
```html
|
|
<van-index-bar :index-list="indexList">
|
|
<van-index-anchor index="1">标题1</van-index-anchor>
|
|
<van-cell title="文本" />
|
|
<van-cell title="文本" />
|
|
<van-cell title="文本" />
|
|
|
|
<van-index-anchor index="2">标题2</van-index-anchor>
|
|
<van-cell title="文本" />
|
|
<van-cell title="文本" />
|
|
<van-cell title="文本" />
|
|
|
|
...
|
|
</van-index-bar>
|
|
```
|
|
|
|
```js
|
|
export default {
|
|
data() {
|
|
return {
|
|
indexList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## API
|
|
|
|
### IndexBar Props
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|------|------|------|------|------|
|
|
| index-list | 索引字符列表 | `Array` | `A-Z` | - |
|
|
| z-index | z-index 层级 | `Number` | `1` | - |
|
|
|
|
### IndexAnchor Props
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|------|------|------|------|------|
|
|
| index | 索引字符 | `String | Number` | - | - |
|
|
|
|
### IndexBar Events
|
|
|
|
| 事件名 | 说明 | 回调参数 |
|
|
|------|------|------|
|
|
| select | 选中字符时触发 | index: 索引字符 |
|
|
|
|
### IndexAnchor Slots
|
|
|
|
| 名称 | 说明 |
|
|
|------|------|
|
|
| default | 锚点位置显示内容,默认为索引字符 |
|