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/useStepper.md
1---2category: Utilities3---45# useStepper67Provides helpers for building a multi-step wizard interface.89## Usage1011### Steps as array1213```ts14import { useStepper } from '@vueuse/core'1516const {17steps,18stepNames,19index,20current,21next,22previous,23isFirst,24isLast,25goTo,26goToNext,27goToPrevious,28goBackTo,29isNext,30isPrevious,31isCurrent,32isBefore,33isAfter,34} = useStepper([35'billing-address',36'terms',37'payment',38])3940// Access the step through `current`41console.log(current.value) // 'billing-address'42```4344### Steps as object4546```ts47import { useStepper } from '@vueuse/core'4849const {50steps,51stepNames,52index,53current,54next,55previous,56isFirst,57isLast,58goTo,59goToNext,60goToPrevious,61goBackTo,62isNext,63isPrevious,64isCurrent,65isBefore,66isAfter,67} = useStepper({68'user-information': {69title: 'User information',70},71'billing-address': {72title: 'Billing address',73},74'terms': {75title: 'Terms',76},77'payment': {78title: 'Payment',79},80})8182// Access the step object through `current`83console.log(current.value.title) // 'User information'84```8586## Type Declarations8788```ts89export interface UseStepperReturn<StepName, Steps, Step> {90/** List of steps. */91steps: Readonly<Ref<Steps>>92/** List of step names. */93stepNames: Readonly<Ref<StepName[]>>94/** Index of the current step. */95index: Ref<number>96/** Current step. */97current: ComputedRef<Step>98/** Next step, or undefined if the current step is the last one. */99next: ComputedRef<StepName | undefined>100/** Previous step, or undefined if the current step is the first one. */101previous: ComputedRef<StepName | undefined>102/** Whether the current step is the first one. */103isFirst: ComputedRef<boolean>104/** Whether the current step is the last one. */105isLast: ComputedRef<boolean>106/** Get the step at the specified index. */107at: (index: number) => Step | undefined108/** Get a step by the specified name. */109get: (step: StepName) => Step | undefined110/** Go to the specified step. */111goTo: (step: StepName) => void112/** Go to the next step. Does nothing if the current step is the last one. */113goToNext: () => void114/** Go to the previous step. Does nothing if the current step is the previous one. */115goToPrevious: () => void116/** Go back to the given step, only if the current step is after. */117goBackTo: (step: StepName) => void118/** Checks whether the given step is the next step. */119isNext: (step: StepName) => boolean120/** Checks whether the given step is the previous step. */121isPrevious: (step: StepName) => boolean122/** Checks whether the given step is the current step. */123isCurrent: (step: StepName) => boolean124/** Checks if the current step is before the given step. */125isBefore: (step: StepName) => boolean126/** Checks if the current step is after the given step. */127isAfter: (step: StepName) => boolean128}129export declare function useStepper<T extends string | number>(130steps: MaybeRef<T[]>,131initialStep?: T,132): UseStepperReturn<T, T[], T>133export declare function useStepper<T extends Record<string, any>>(134steps: MaybeRef<T>,135initialStep?: keyof T,136): UseStepperReturn<Exclude<keyof T, symbol>, T, T[keyof T]>137```138