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/useCounter.md
1---2category: Utilities3---45# useCounter67Basic counter with utility functions.89## Basic Usage1011```ts12import { useCounter } from '@vueuse/core'1314const { count, inc, dec, set, reset } = useCounter()15```1617## Usage with options1819```ts20import { useCounter } from '@vueuse/core'2122const { count, inc, dec, set, reset } = useCounter(1, { min: 0, max: 16 })23```2425## Type Declarations2627```ts28export interface UseCounterOptions {29min?: number30max?: number31}32export interface UseCounterReturn {33/**34* The current value of the counter.35*/36readonly count: Readonly<Ref<number>>37/**38* Increment the counter.39*40* @param {number} [delta=1] The number to increment.41*/42inc: (delta?: number) => void43/**44* Decrement the counter.45*46* @param {number} [delta=1] The number to decrement.47*/48dec: (delta?: number) => void49/**50* Get the current value of the counter.51*/52get: () => number53/**54* Set the counter to a new value.55*56* @param val The new value of the counter.57*/58set: (val: number) => void59/**60* Reset the counter to an initial value.61*/62reset: (val?: number) => number63}64/**65* Basic counter with utility functions.66*67* @see https://vueuse.org/useCounter68* @param [initialValue]69* @param options70*/71export declare function useCounter(72initialValue?: MaybeRef<number>,73options?: UseCounterOptions,74): {75count: Readonly<76| Ref<number, number>77| ShallowRef<number, number>78| WritableComputedRef<number, number>79>80inc: (delta?: number) => number81dec: (delta?: number) => number82get: () => number83set: (val: number) => number84reset: (val?: number) => number85}86```87