useCounter ​
Basic counter with utility functions.
Demo ​
Count: 0
Basic Usage ​
js
import { useCounter } from '@vueuse/core'
const { count, inc, dec, set, reset } = useCounter()
Usage with options ​
js
import { useCounter } from '@vueuse/core'
const { count, inc, dec, set, reset } = useCounter(1, { min: 0, max: 16 })
Type Declarations ​
typescript
export interface UseCounterOptions {
min?: number
max?: number
}
/**
* Basic counter with utility functions.
*
* @see https://vueuse.org/useCounter
* @param [initialValue]
* @param options
*/
export declare function useCounter(
initialValue?: MaybeRef<number>,
options?: UseCounterOptions,
): {
count: Ref<number, MaybeRef<number>>
inc: (delta?: number) => number
dec: (delta?: number) => number
get: () => number
set: (val: number) => number
reset: (val?: number) => number
}
Source ​
Contributors ​
Anthony Fu
Anthony Fu
Tycho
leewakin
Rock070
iChengbo
Damien Roche
Alex Kozack