Skip to content

useCounter

类别
导出体积
247 B
上次更改
2 months ago

基础计数器,带有工具函数。

示例

计数: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
}

源码

源码演示文档

贡献者

Anthony Fu
一纸忘忧
Anthony Fu
Tycho
leewakin
Rock070
iChengbo
Damien Roche
Alex Kozack

更新日志

v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.8.0 on 2/20/2024
cf29c - fix: allow delta to be negative (#3650)
v10.3.0 on 7/30/2023
6ae3a - feat: initialValue support ref (#3266)