重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
vueuse-math-skilld by harlan-zw/vue-ecosystem-skills
npx skills add https://github.com/harlan-zw/vue-ecosystem-skills --skill vueuse-math-skilld@vueuse/mathVueUse 的数学函数
版本: 14.2.1 依赖: @vueuse/shared@14.2.1 标签: alpha: 14.0.0-alpha.3, beta: 14.0.0-beta.1, latest: 14.2.1
参考: GitHub Issues — 错误、变通方案、边界情况 • GitHub Discussions — 问答、模式、示例 • Releases — 更新日志、破坏性变更、新 API
本节记录特定版本的 API 变更 — 优先关注近期的主要/次要版本。
已弃用: and、or、not — v14 中已弃用,建议使用原始名称 logicAnd、、
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
logicOrlogicNot破坏性变更: 需要 Vue 3.5+ — v14 将最低 Vue 版本提升至 3.5,以启用原生的 useTemplateRef 和 MaybeRefOrGetter 来源
破坏性变更: 仅支持 ESM — v13 完全移除了对 CommonJS (CJS) 的支持 来源
新增: useAverage — 响应式地计算数组或可变参数的算术平均值
新增: useSum — 响应式地计算数组或可变参数的总和
新增: createProjection — 创建可在两个数值域之间复用的数值投影器
新增: createGenericProjection — 创建带有自定义映射函数的投影器,适用于任意类型
新增: usePrecision — 选项现在包含 math 属性,用于指定舍入策略 (floor、ceil、round)
新增: useClamp — 当输入是 getter 或只读 ref 时,返回 ComputedRef 而非 Ref
新增: useMath — 通过键名提供对任何标准 Math 方法的响应式访问
新增: logicAnd、logicOr、logicNot — 支持多个 ref 的可变参数响应式布尔逻辑
新增: useMax、useMin — 支持数组和可变参数,用于响应式比较
新增: useAbs、useCeil、useFloor、useRound、useTrunc — 针对常见 Math 方法的专用响应式包装器
新增: useProjection — 从一个数值域到另一个数值域的响应式数值投影
其他变更: tsdown 构建系统 v14 · WatchSource<T> 类型 v14 · MaybeRefOrGetter 原生支持 v12.8
将 useClamp 与可变的 ref 一起使用,以创建自我验证的状态。当传入可变 ref 时,它会返回一个可写的计算属性,自动钳制分配给它的任何值 来源
// 推荐:防止无效的状态赋值 const value = useClamp(shallowRef(0), 0, 10) value.value = 15 // 状态保持为 10
在 useProjection 中为域传递响应式数组以处理动态缩放。这对于可缩放图表或响应式滑块等 UI 元素是首选,因为这些元素的输入/输出边界会随时间变化 来源
在组件逻辑外部使用 createProjection 定义可复用的映射器。这确保了应用程序不同部分之间缩放的一致性,并减少了重新定义域的开销 来源
在聚合组合式函数中利用剩余参数进行临时计算。useSum、useAverage、useMax 和 useMin 直接接受多个 ref,避免了创建中间数组 ref 的需要
// 推荐:对于固定的 ref 集合,语法更简洁 const total = useSum(refA, refB, refC)
对于数值操作,优先使用 usePrecision 而非 toFixed。usePrecision 返回一个 number,这可以防止类型强制转换错误,并允许在不重新解析字符串的情况下进行进一步的数学运算 来源
在 usePrecision 中使用显式的舍入模式以满足特定的 UI 需求。传递 math 选项 ('floor' | 'ceil' | 'round') 来控制分页器或进度条中如何处理小数值 来源
将 logicAnd 或 logicOr 与 @vueuse/core 的 whenever 结合使用,以实现更简洁的副作用。当基于多个响应式标志触发操作时,这种模式比复杂的手动 computed 属性更具可读性 来源
使用 createGenericProjection 进行非线性域映射。提供一个自定义的投影器函数来处理对数刻度或数值域之间的自定义缓动过渡 来源
使用 useMath 从标准 Math 方法中响应式地派生值。它会自动包装多个参数,并确保当任何输入依赖项发生变化时结果都会更新 来源
在模板中使用 logicNot 进行响应式布尔值取反。在定义可见性或禁用状态时,它比 !ref.value 或手动 computed 包装器更能清晰地表达意图
每周安装量
54
代码仓库
GitHub 星标数
148
首次出现
2026年2月19日
安全审计
已安装于
github-copilot42
opencode39
claude-code38
codex38
gemini-cli38
kimi-cli37
@vueuse/mathMath functions for VueUse
Version: 14.2.1 Deps: @vueuse/shared@14.2.1 Tags: alpha: 14.0.0-alpha.3, beta: 14.0.0-beta.1, latest: 14.2.1
References: GitHub Issues — bugs, workarounds, edge cases • GitHub Discussions — Q&A, patterns, recipes • Releases — changelog, breaking changes, new APIs
This section documents version-specific API changes — prioritize recent major/minor releases.
DEPRECATED: and, or, not — v14 deprecated in favor of original names logicAnd, logicOr, logicNot source
BREAKING: Requires Vue 3.5+ — v14 moved to Vue 3.5 as minimum version, enabling native useTemplateRef and MaybeRefOrGetter source
BREAKING: ESM-only — v13 dropped CommonJS (CJS) support entirely source
NEW: useAverage — reactively calculate average from an array or variadic arguments
NEW: useSum — reactively calculate sum from an array or variadic arguments
NEW: createProjection — create a reusable numeric projector between two numeric domains
NEW: createGenericProjection — create a projector with a custom mapping function for arbitrary types
NEW: usePrecision — options now include math property for rounding strategy (floor, ceil, round)
NEW: useClamp — returns ComputedRef instead of Ref when input is a getter or readonly ref
NEW: useMath — provides reactive access to any standard Math method via key name
NEW: logicAnd, logicOr, logicNot — variadic reactive boolean logic supporting multiple refs
NEW: useMax, useMin — support both array and variadic arguments for reactive comparison
NEW: useAbs, useCeil, useFloor, useRound, useTrunc — dedicated reactive wrappers for common Math methods
NEW: useProjection — reactive numeric projection from one domain to another
Also changed: tsdown build system v14 · WatchSource<T> types v14 · MaybeRefOrGetter native v12.8
Use useClamp with a mutable ref to create a self-validating state. When a mutable ref is passed, it returns a writable computed that automatically clamps any value assigned to it source
// Preferred: prevents invalid state assignment const value = useClamp(shallowRef(0), 0, 10) value.value = 15 // state remains 10
Pass reactive arrays for domains in useProjection to handle dynamic scaling. This is preferred for UI elements like zoomable charts or responsive sliders where the input/output boundaries change over time source
Define reusable mappers with createProjection outside component logic. This ensures consistent scaling across different parts of the application and reduces the overhead of redefining domains source
Leverage rest arguments in aggregation composables for ad-hoc calculations. useSum, , , and accept multiple refs directly, avoiding the need to create intermediate array refs
Weekly Installs
54
Repository
GitHub Stars
148
First Seen
Feb 19, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
github-copilot42
opencode39
claude-code38
codex38
gemini-cli38
kimi-cli37
Flutter应用架构设计指南:分层结构、数据层实现与最佳实践
5,900 周安装
WordPress 7.0主题开发工作流:从零创建支持区块编辑器的自定义主题
106 周安装
SAELens:稀疏自编码器训练库,实现神经网络机制可解释性分析
108 周安装
PyTorch Lightning教程:高级深度学习训练框架,简化PyTorch代码,支持分布式训练
109 周安装
自动解决PR机器人审查:AI辅助修复Copilot、Cursor Bugbot、CodeRabbit等发现的问题
107 周安装
Databricks Python SDK 开发指南:SDK、Connect、CLI 与 REST API 完整教程
104 周安装
英文转中文翻译器:保留句子结构的AI翻译工具,支持.txt/.md文件翻译
107 周安装
useAverageuseMaxuseMin// Preferred: cleaner syntax for fixed sets of refs const total = useSum(refA, refB, refC)
Prefer usePrecision over toFixed for numeric operations. usePrecision returns a number, which prevents type-coercion bugs and allows further mathematical operations without re-parsing strings source
Use explicit rounding modes in usePrecision for specific UI requirements. Pass the math option ('floor' | 'ceil' | 'round') to control how fractional values are handled in paginators or progress bars source
Combine logicAnd or logicOr with @vueuse/core's whenever for cleaner side effects. This pattern is more readable than complex manual computed properties when triggering actions based on multiple reactive flags source
Employ createGenericProjection for non-linear domain mapping. Provide a custom projector function to handle logarithmic scales or custom eased transitions between numeric domains source
Use useMath to reactively derive values from standard Math methods. It automatically wraps multiple arguments and ensures the result updates whenever any input dependency changes source
Use logicNot for reactive boolean inversion in templates. It expresses intent more clearly than !ref.value or manual computed wrappers when defining visibility or disabled states