Categories: Vant 教程

Vant IndexBar 索引栏

引入

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-index z-index 层级 number | string 1
sticky 是否开启锚点自动吸顶 boolean true
sticky-offset-top v2.0.7 锚点自动吸顶时与顶部的距离 number 0
highlight-color 索引字符高亮颜色 string #07c160

IndexAnchor Props

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

IndexBar Events

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

IndexAnchor Slots

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

实例演示

冒牌SEO

前端开发者,欢迎大家一起沟通和交流。

Share
Published by
冒牌SEO

Recent Posts

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

5 天 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

2 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

2 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

3 周 ago

聊聊React和Vue组件更新的实现及区别

React 和 Vue 都是当…

3 周 ago