主题
useCounter
具有实用函数的基本计数器。
¥Basic counter with utility functions.
示例
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 })
类型声明
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
}