索引列表组件,可以通过点击索引导航,快速定位到列表处
在 Taro 文件中引入组件
import { AtIndexes } from 'taro-ui-vue3'
组件依赖的样式文件(仅按需引用时需要)
@import "taro-ui-vue3/dist/style/components/indexes.scss";
说明:
height: 100vh
。<template>
<view class="page" style="height: 100vh;">
<!-- 基础用法 -->
<view style="height: 100%;">
<AtIndexes
:list="mockData"
topKey="Top"
@click="onClick"
@scroll-into-view="handleScroll"
>
<view class="custom-area">
用户自定义内容
<AtSearchBar
:value="value"
@change="handleChange"
placeholder="跳转到指定Key"
@action-click="handleActionClick"
/>
</view>
</AtIndexes>
</view>
</view>
</template>
<template>
<view>
<AtIndexes
:list="list"
@scroll-into-view="handleScroll"
>
<view class='custom-area'>
用户自定义内容
<AtSearchBar
placeholder='跳转到指定Key'
@action-click="handleActionClick"
/>
</view>
</AtIndexes>
</view>
</template>
<script>
import mockData from './mock-data'
export default {
name: 'AtIndexesDemo',
data() {
return {
value: '',
list: mockData,
scrollToView: null
}
},
methods: {
handleActionClick() {
if (!this.value) {
return
}
this.scrollToView && this.scrollToView(this.value.toUpperCase())
this.value = ''
},
handleScroll(fn) {
this.scrollToView = fn
}
}
}
</script>
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
animation | 是否开启跳转过渡动画 | Boolean | - | false |
isVibrate | 是否切换 key 的震动,只在微信小程序有效 | Boolean | - | true |
isShowToast | 是否用弹框显示当前 key | Boolean | - | true |
topKey | 右侧导航第一个名称 | String | - | Top |
list | [ {'{title:列表标题,key:右侧导航标题,items:[{name: 列表项内容}]}'}] | Array | - | - |
事件名称 | 说明 | 返回参数 |
---|---|---|
onClick | 点击列表项触发事件 | (item:Object,event) => void |
onScrollIntoView | 获取跳转事件跳转到指定key | (fn:Function) => void |