useCounter
基础计数器,带有工具函数。
Demo
计数:0
基本用法
js
import { useCounter } from '@vueuse/core'
const { count, inc, dec, set, reset } = useCounter()
带有选项的用法
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
}
/**
* 基础计数器,带有工具函数。
*
* @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
贡献者
Anthony Fu
丶远方
Anthony Fu
Tycho
leewakin
Rock070
iChengbo
Damien Roche
Alex Kozack