Vant IndexBar 索引栏

2022-05-31 13:39 更新

引入

import Vue from 'vue';
import { IndexBar, IndexAnchor } from 'vant';

Vue.use(IndexBar);
Vue.use(IndexAnchor);

代码演示

基础用法

点击索引栏时,会自动跳转到对应的IndexAnchor锚点位置

<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属性自定义展示的索引字符列表,

<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>
export default {
  data() {
    return {
      indexList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    }
  }
}

API

IndexBar Props

参数说明类型默认值
index-list索引字符列表string[] | number[]A-Z
z-indexz-index 层级number | string1
sticky是否开启锚点自动吸顶booleantrue
sticky-offset-top v2.0.7锚点自动吸顶时与顶部的距离number0
highlight-color索引字符高亮颜色string#07c160

IndexAnchor Props

参数说明类型默认值
index索引字符number | string-

IndexBar Events

事件名说明回调参数
select选中字符时触发index: 索引字符

IndexAnchor Slots

名称说明
default锚点位置显示内容,默认为索引字符


实例演示

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号