IndexList 索引列表

通过折叠面板收纳内容区域
平台差异说明
| APP | H5 | 微信小程序 | 支付宝小程序 | QQ小程序 | ··· |
|---|---|---|---|---|---|
| √ | √ | √ | √ | √ | 适配中 |
代码示例
部分功能示例,具体可参考示例程序以及文档API。
基础用法
通过外层包裹一个 index-list 组件,内部描点通过 index-anchor 组件参入,自定义列表内容通过 index-item 组件嵌套使用
- 通过
indexList属性自定义索引字符列表 - nvue需要将
index-anchor组件写在index-item组件的外部 - 非nvue需要将
index-anchor组件嵌套在index-item组件内部
html
<template>
<fu-index-list>
<template v-for="(item, index) in list">
<!-- #ifdef APP-NVUE -->
<fu-index-anchor :text="indexList[index]"></fu-index-anchor>
<!-- #endif -->
<fu-index-item>
<!-- #ifndef APP-NVUE -->
<fu-index-anchor :text="indexList[index]"></fu-index-anchor>
<!-- #endif -->
<view class="list-cell" v-for="(cell, index) in item">
{{cell}}
</view>
</fu-index-item>
</template>
</fu-index-list>
</template>
<script setup>
import { ref } from 'vue';
// data数据
const indexList = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
const list = [
['列表A1', '列表A2', '列表A3'],
['列表B1', '列表B2', '列表B3'],
['列表C1', '列表C2', '列表C3'],
['列表D1', '列表D2', '列表D3'],
['列表E1', '列表E2', '列表E3'],
['列表F1', '列表F2', '列表F3'],
['列表G1', '列表G2', '列表G3']
];
</script>
<style lang="scss" scoped>
.list-cell {
/* #ifndef APP-PLUS */
display: flex;
box-sizing: border-box;
width: 100%;
/* #endif */
padding: 10px 24rpx;
overflow: hidden;
color: #323233;
font-size: 14px;
line-height: 24px;
background-color: #fff;
}
</style>设置自定义导航栏
默认情况下,组件的描点是吸附在导航栏下方的,如果您修改了导航栏,比如取消导航栏或者自定义导航栏,就需要指定吸顶的高度,也就是 customNavHeight 属性的值,注意:这个值的单位为 px
- 如果自定义导航栏,需要
customNavHeight属性设置为导航栏的高度
API
IndexList Props
| 属性名 | 说明 | 类型 | 默认值 | 可选值 |
|---|---|---|---|---|
| inactiveColor | 右边锚点非激活的颜色- | String | #686b6f | - |
| activeColor | 右边锚点激活的颜色 | String | #2979ff | - |
| indexList | 索引字符列表 | Array | A-Z | - |
| sticky | 是否吸顶 | Boolean | true | false |
| customNavHeight | 自定义导航栏高度 | String|Number | 0 | - |
IndexList Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| select | 选中右边索引字符时触发 | () => void |
IndexList Slot
| 名称 | 说明 |
|---|---|
| header | 自定义索引列表头部内容 |
| footer | 自定义索引列表底部内容 |
| default | 嵌套 index-item 组件 |
indexAnchor Props
| 属性名 | 说明 | 类型 | 默认值 | 可选值 |
|---|---|---|---|---|
| text | 列表锚点文本内容 | String|Number | - | - |
| color | 列表锚点文字颜色 | String | #5c5e62 | - |
| size | 列表锚点文字大小 | String|Number | 14 | - |
| bgColor | 列表锚点背景颜色 | String | #f6f6f6 | - |
| height | 列表锚点高度 | String|Number | 32 | - |
indexItem Slot
| 名称 | 说明 |
|---|---|
| default | 自定义列表内容 |