Skip to content

useProjection

类别
导出体积
163 B
依赖包
@vueuse/math
上次更改
2 months ago
相关

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

示例

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

类型声明

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

源码

源码演示文档

贡献者

一纸忘忧
Anthony Fu
IlyaL
Anthony Fu
SerKo
Robin
Curt Grimes
Wenlu Wang

更新日志

d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)