useClamp
在两个其他值之间响应式地夹取一个值。
示例
min: max: value:0
用法
ts
import { useClamp } from '@vueuse/math'
const min = ref(0)
const max = ref(10)
const value = useClamp(0, min, max)
你也可以传递一个 ref
,当源 ref
发生变化时,返回的 computed
将会被更新:
ts
import { useClamp } from '@vueuse/math'
const number = ref(0)
const clamped = useClamp(number, 0, 10)
类型声明
typescript
export declare function useClamp(
value: ReadonlyRefOrGetter<number>,
min: MaybeRefOrGetter<number>,
max: MaybeRefOrGetter<number>,
): ComputedRef<number>
export declare function useClamp(
value: MaybeRefOrGetter<number>,
min: MaybeRefOrGetter<number>,
max: MaybeRefOrGetter<number>,
): Ref<number>
源码
贡献者
Anthony Fu
一纸忘忧
Anthony Fu
ClemDee
更新日志
v12.3.0
on 1/2/202559f75
- feat(toValue): deprecate toValue
from @vueuse/shared
in favor of Vue's nativev12.0.0-beta.1
on 11/21/2024v10.0.0-beta.5
on 4/13/2023cb644
- refactor!: remove isFunction
and isString
utilsv10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
0a72b
- feat(toValue): rename resolveUnref
to toValue
v9.13.0
on 2/18/2023