ScrollTab/ScrollTabItem 标签滚动布局
vue
<template>
<ta-group class="exp-scrollTab" title="基础用法">
<!-- <div class="exp-scrollTab-header">占位头部</div> -->
<ta-scroll-tab
ref="scrollTabRef"
class="exp-scrollTab-boxes"
:sideBar="true"
:enablePullRefreshDown="true"
:enablePullRefreshUp="true"
:documentContainer="true"
:pullRefreshTexts="texts"
v-model="value"
:stickyOffsetTop="offsetTop"
:stickyOffsetBottom="offsetBottom"
@change="onChange"
@pullRefreshing="onPullRefreshing"
>
<ta-scroll-tab-item name="Dust Red">
<div class="exp-scrollTab-box box-1"></div>
</ta-scroll-tab-item>
<ta-scroll-tab-item name="Volcano">
<div class="exp-scrollTab-box box-2"></div
></ta-scroll-tab-item>
<ta-scroll-tab-item name="Sunset Orange">
<div class="exp-scrollTab-box box-3"></div
></ta-scroll-tab-item>
<ta-scroll-tab-item name="Calendula Gold">
<div class="exp-scrollTab-box box-4"></div
></ta-scroll-tab-item>
<ta-scroll-tab-item name="Sunrise Yellow">
<div class="exp-scrollTab-box box-5"></div
></ta-scroll-tab-item>
<ta-scroll-tab-item name="Lime">
<div class="exp-scrollTab-box box-6"></div
></ta-scroll-tab-item>
<ta-scroll-tab-item name="Polar Green">
<div class="exp-scrollTab-box box-7"></div
></ta-scroll-tab-item>
<ta-scroll-tab-item name="Cyan">
<div class="exp-scrollTab-box box-8"></div
></ta-scroll-tab-item>
<ta-scroll-tab-item name="Daybreak Blue">
<div class="exp-scrollTab-box box-9"></div
></ta-scroll-tab-item>
<ta-scroll-tab-item name="Geek Blue">
<div class="exp-scrollTab-box box-10"></div
></ta-scroll-tab-item>
<ta-scroll-tab-item name="Golden Purple">
<div class="exp-scrollTab-box box-11"></div
></ta-scroll-tab-item>
<ta-scroll-tab-item name="Magenta">
<div class="exp-scrollTab-box box-12"></div
></ta-scroll-tab-item>
</ta-scroll-tab>
</ta-group>
</template>
<script lang="ts">
import { defineComponent, onMounted, ref } from 'vue'
import type {
ScrollTabOnChange,
ScrollTabOnPullRefreshing,
ScrollTabPullRefreshTexts,
ScrollTabRef
} from '@/index'
export default defineComponent({
name: 'ExpScrollTab',
setup() {
const scrollTabRef = ref<ScrollTabRef | null>(null)
const value = ref('Dust Red')
const onChange: ScrollTabOnChange = res => {
console.log('change', res)
}
const onPullRefreshing: ScrollTabOnPullRefreshing = ({ pullDirection }, loadComplete) => {
console.log(pullDirection)
setTimeout(() => loadComplete(), 2000)
}
const texts: ScrollTabPullRefreshTexts = {
pullingDown: '下拉刷新2',
holding: '松开刷新2',
refreshing: '刷新中2'
}
onMounted(() => {
// scrollTabRef.value?.scrollToIndex(2)
})
return {
value,
scrollTabRef,
offsetTop: 52,
offsetBottom: 12,
texts,
onPullRefreshing,
onChange
}
}
})
</script>
Import
js
import { TaScrollTab, TaScrollTabItem } from 'tantalum-ui-mobile'
具体的引入方式可以参考引入组件。
Import Type
组件导出的类型定义:
ts
import type { ScrollTabOnChange, ScrollTabRef } from 'tantalum-ui-mobile'
ScrollTab
ScrollTab Props
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
sticky-offset-top | string | number | 0 | 否 | 数值默认是 px,也支持 vw/vh |
sticky-offset-bottom | string | number | 0 | 否 | 数值默认是 px,也支持 vw/vh |
side-bar | boolean | true | 否 | 使用侧边 Tab |
ScrollTab Events
事件 | 描述 | 回调函数参数 | TypeScript 函数 |
---|---|---|---|
change | 切换时触发 | (name: string, activeIndex: number) | ScrollTabOnChange |
refreshing | 下拉刷新时触发 | payload: ( pullDirection: 'up' | 'down', done: () => void ) 其中 pullDirection 指下拉的方向,done 指刷新完毕回调的函数 | ScrollTabOnPullRefreshing |
scroll | 滚动时触发 | payload: { scrollLeft: number, scrollTop: number, scrollWidth: number, scrollHeight: number } | ScrollTabOnScroll |
ScrollTab Slots
#default
注:其中只可放置 ScrollTabItem 组件,否则会导致未定义的行为。
vue
<ta-scroll-tab>
<ta-scroll-tab-item name="Dust Red">
<div class="scroll-tab-box box-1"></div>
</ta-scroll-tab-item>
<ta-scroll-tab-item name="Volcano">
<div class="scroll-tab-box box-2"></div>
</ta-scroll-tab-item>
<ta-scroll-tab-item name="Sunset Orange">
<div class="scroll-tab-box box-3"></div>
</ta-scroll-tab-item>
...
</ta-scroll-tab>
Methods
ts
interface ScrollTabRef {
scrollTo: (name: string) => void
scrollToIndex: (index: number) => void
}
方法名 | 说明 |
---|---|
scrollTo | 切换到指定 name 的 Item |
scrollToIndex | 切换到指定 index 的 Item |
ScrollTabItem
ScrollTabItem Props
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
name | string | 是 | 唯一标识,设置后配合 ScrollTab 组件的 v-model 和 change 使用 | |
title | string | 否 | 分组名,也应用于吸附,如果没有设置则获取 name 的值 |
ScrollTabItem Slots
#default
vue
<ta-scroll-tab-item name="Dust Red">
<div class="scroll-tab-box box-1"></div>
</ta-scroll-tab-item>