Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useCycleList.md
1---2category: Utilities3---45# useCycleList67Cycle through a list of items.89<CourseLink href="https://vueschool.io/lessons/create-an-image-carousel-with-vueuse?friend=vueuse">Learn how to use useCycleList to create an image carousel with this FREE video lesson from Vue School!</CourseLink>1011## Usage1213```ts14import { useCycleList } from '@vueuse/core'1516const { state, next, prev, go } = useCycleList([17'Dog',18'Cat',19'Lizard',20'Shark',21'Whale',22'Dolphin',23'Octopus',24'Seal',25])2627console.log(state.value) // 'Dog'2829prev()3031console.log(state.value) // 'Seal'3233go(3)3435console.log(state.value) // 'Shark'36```3738## Type Declarations3940```ts41export interface UseCycleListOptions<T> {42/**43* The initial value of the state.44* A ref can be provided to reuse.45*/46initialValue?: MaybeRef<T>47/**48* The default index when49*/50fallbackIndex?: number51/**52* Custom function to get the index of the current value.53*/54getIndexOf?: (value: T, list: T[]) => number55}56/**57* Cycle through a list of items58*59* @see https://vueuse.org/useCycleList60*/61export declare function useCycleList<T>(62list: MaybeRefOrGetter<T[]>,63options?: UseCycleListOptions<T>,64): UseCycleListReturn<T>65export interface UseCycleListReturn<T> {66state: ShallowRef<T>67index: WritableComputedRef<number>68next: (n?: number) => T69prev: (n?: number) => T70/**71* Go to a specific index72*/73go: (i: number) => T74}75```76