Skip to content

useProjection

Category
Export Size
196 B
Package
@vueuse/math
Last Changed
6 months ago
Related

从一个域映射到另一个域的响应式数值投影。

Demo

Projection from [0, 10] to [10, 100]
Input: 0
Output: 10

用法

ts
import { useProjection } from '@vueuse/math'

const input = ref(0)
const projected = useProjection(input, [0, 10], [0, 100])

input.value = 5 // projected.value === 50
input.value = 10 // projected.value === 100

类型声明

typescript
/**
 * 从一个域映射到另一个域的响应式数值投影。
 *
 * @see https://vueuse.org/useProjection
 */
export declare function useProjection(
  input: MaybeRefOrGetter<number>,
  fromDomain: MaybeRefOrGetter<readonly [number, number]>,
  toDomain: MaybeRefOrGetter<readonly [number, number]>,
  projector?: ProjectorFunction<number, number>,
): ComputedRef<number>

Source

SourceDemoDocs

贡献者

Anthony Fu
丶远方
Anthony Fu
Curt Grimes
Wenlu Wang

变更日志

v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter

Released under the MIT License.