SlideGroup
Displays a horizontal list with selection, active-item positioning and boundary action slots.
Import
Use <hui-slide-group> after configuring uni-app easycom. Import public types and functions from @nscode/handy-uni. Ordinary Vue applications install the @nscode/handy-uni/web preview plugin.
Examples
Each example is standalone. Controls show the current value or event result on the page.
<template>
<view>
<hui-slide-group
v-model="selected"
:items="items"
item-key="id"
selectable
active-position="center"
@boundary-change="(value) => (lastEvent = 'boundary-change:' + JSON.stringify(value))"
@change="onChange"
@click="onClick"
>
<template #item="{ index, active }"
><hui-tag :type="active ? 'primary' : 'info'">{{ items[index].label }}</hui-tag></template
>
<template #suffix="{ atEnd, scrollNext }"
><hui-button :disabled="atEnd" @click="scrollNext">后移 / Next</hui-button></template
> </hui-slide-group
><text>{{ selected }} / {{ lastEvent }}</text>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('尚无事件 / No event')
const selected = ref<string | number>(0)
const onChange = (key: string | number, context: { item: unknown; index: number }) => {
lastEvent.value = JSON.stringify({ key, context })
}
const onClick = (item: unknown, context: { index: number }) => {
lastEvent.value = JSON.stringify({ item, context })
}
const items = Array.from({ length: 12 }, (_, id) => ({ id, label: '栏目 / Section ' + id }))
</script>
Props
| Prop | Type | Default | Details |
|---|---|---|---|
items | unknown[] | [] | Data items rendered in source order. |
itemKey | string | ((item: unknown, index: number) => string | number) | — | Stable object field or key getter; falls back to id, then index. |
modelValue | string | number | — | Controlled current value; accept update:modelValue to change it. |
defaultValue | string | number | — | Initial uncontrolled value. |
selectable | boolean | false | Enables selection and change events. |
activePosition | SlideGroupActivePosition | 'center' | How the active item is aligned: auto, start or center. |
gap | number | 8 | Spacing in px; Waterfall accepts horizontal and vertical values. |
padding | number | 16 | Inner horizontal padding in px. |
fade | boolean | false | Displays an edge fade when more content is available. |
animated | boolean | true | Enables animation; browser reduced-motion preferences take priority. |
Root classes and styles use customClass and customStyle. Numbers representing dimensions use px; durations use ms unless explicitly documented.
Events
| Event | Arguments |
|---|---|
update:modelValue | (key: string | number) |
change | (key: string | number, context: { item: unknown; index: number }) |
click | (item: unknown, context: { index: number }) |
boundary-change | (state: SlideGroupBoundary) |
Controlled state only changes when the parent accepts its update event. Events with multiple words use kebab-case. Disabled or stale asynchronous actions do not emit a successful state change.
Slots
| Slot | Scope |
|---|---|
prefix | { atStart, atEnd, scrollPrev, scrollNext } |
item | { item, index, active } |
suffix | { atStart, atEnd, scrollPrev, scrollNext } |
Methods
| Method | Signature | Description |
|---|---|---|
scrollToIndex | (index: number): Promise<void> | Scroll to an item index. |
scrollPrev | (): void | Scroll toward the previous viewport. |
scrollNext | (): void | Scroll toward the next viewport. |
refresh | (): Promise<void> | Measure again and update state. |
Types
SlideGroupActivePosition、SlideGroupBoundary、SlideGroupProps、SlideGroupEmits、SlideGroupExpose.
Platform notes
Supports H5, WeChat mini-program, App-vue and ordinary Vue 3 Web through shared platform components. Unit tests do not replace device acceptance; verify touch, screen readers, deactivation and native rendering on each target.
Device smoke checklist.