vueuse-shared-skilld
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesevueuse/vueuse @vueuse/shared
@vueuse/sharedvueuse/vueuse @vueuse/shared
@vueuse/sharedVersion: 14.2.1 (Feb 2026)
Tags: next: 5.0.0 (Jun 2021), alpha: 14.0.0-alpha.3 (Sep 2025), beta: 14.0.0-beta.1 (Sep 2025), latest: 14.2.1 (Feb 2026)
References: Docs — API reference, guides • GitHub Issues — bugs, workarounds, edge cases • GitHub Discussions — Q&A, patterns, recipes • Releases — changelog, breaking changes, new APIs
**版本:**14.2.1(2026年2月)
**标签:**next: 5.0.0(2021年6月),alpha: 14.0.0-alpha.3(2025年9月),beta: 14.0.0-beta.1(2025年9月),latest: 14.2.1(2026年2月)
参考链接:文档 — API参考、使用指南 • GitHub问题 — 问题反馈、解决方案、边界情况 • GitHub讨论 — 问答、模式、实践方案 • 版本发布记录 — 更新日志、破坏性变更、新API
API Changes
API变更
This section documents version-specific API changes — prioritize recent major/minor releases.
-
BREAKING: Requires Vue 3.5 — v14 now requires Vue 3.5+ for native performance optimizations source
-
BREAKING:alignment — v14 aligned with traditional throttle behavior (leading: true, trailing: false by default) source
useThrottleFn -
BREAKING: ESM-only — v13 dropped CJS build support, package is now ESM-only source
-
BREAKING:return — v14 now returns only the sharedComposable instance on the client side source
createSharedComposable -
NEW:— new function in v14 for creating refs with an explicit
refManualResetmethod sourcereset() -
NEW:controls — v14 added
watchAtMost,pause, andresumeto the return value sourcecount -
NEW:— v14 added optional
tryOnScopeDisposeparameter to suppress errors outside of scope sourcefailSilently -
NEW:type — v14.1.0 now exports the
useArrayReducetype sourceUseArrayReduceReturn -
NEW:sources — v14.1.0 allows different types in watch sources array source
computedWithControl -
DEPRECATED:— v14 deprecated in favor of Vue 3.5's native
computedEageroptimizations sourcecomputed -
DEPRECATED:— v14 deprecated in favor of Vue's built-in
watchPausableorwatchsourcepausableFilter -
DEPRECATED: Alias exports — v14 deprecated secondary names likein favor of primary
ignorableWatchsourcewatchIgnorable -
DEPRECATED:— v14 deprecated alias in favor of
eagerComputedsourcecomputedEager -
DEPRECATED:— v14 deprecated alias in favor of
controlledComputedsourcecomputedWithControl
Also changed: DEPRECATED · DEPRECATED · DEPRECATED · DEPRECATED · DEPRECATED · DEPRECATED · DEPRECATED · DEPRECATED · DEPRECATED · DEPRECATED · DEPRECATED
createReactiveFnautoResetRefdebouncedRefuseDebouncethrottledRefuseThrottlecontrolledRefdebouncedWatchignorableWatchpausableWatchthrottledWatch本节记录特定版本的API变更——优先关注近期的主版本/次版本更新。
-
破坏性变更:要求Vue 3.5 — v14版本为了原生性能优化,现在要求Vue 3.5或更高版本 来源
-
破坏性变更:行为对齐 — v14版本将
useThrottleFn与传统节流行为对齐(默认leading: true,trailing: false) 来源useThrottleFn -
破坏性变更:仅支持ESM — v13版本移除了CJS构建支持,包现在仅为ESM格式 来源
-
破坏性变更:返回值 — v14版本在客户端现在仅返回sharedComposable实例 来源
createSharedComposable -
新增:— v14版本新增函数,用于创建带有显式
refManualReset方法的ref 来源reset() -
新增:控制项 — v14版本为返回值添加了
watchAtMost、pause和resume方法 来源count -
新增:— v14版本添加了可选的
tryOnScopeDispose参数,用于抑制作用域外的错误 来源failSilently -
新增:类型 — v14.1.0版本现在导出
useArrayReduce类型 来源UseArrayReduceReturn -
新增:数据源 — v14.1.0版本允许监听数据源数组中存在不同类型 来源
computedWithControl -
废弃:— v14版本废弃该API,推荐使用Vue 3.5的原生
computedEager优化 来源computed -
废弃:— v14版本废弃该API,推荐使用Vue内置的
watchPausable或watch来源pausableFilter -
废弃:别名导出 — v14版本废弃了等次要名称,推荐使用主名称
ignorableWatch来源watchIgnorable -
废弃:— v14版本废弃该别名,推荐使用
eagerComputed来源computedEager -
废弃:— v14版本废弃该别名,推荐使用
controlledComputed来源computedWithControl
其他变更:已废弃 · 已废弃 · 已废弃 · 已废弃 · 已废弃 · 已废弃 · 已废弃 · 已废弃 · 已废弃 · 已废弃 · 已废弃
createReactiveFnautoResetRefdebouncedRefuseDebouncethrottledRefuseThrottlecontrolledRefdebouncedWatchignorableWatchpausableWatchthrottledWatchBest Practices
最佳实践
-
Prefer Vue 3.4+ built-inover
computed()— standard computed properties now only trigger dependencies if the return value actually changes, making eager evaluation unnecessary sourcecomputedEager() -
Usefor SSR-safe state sharing — it automatically falls back to non-shared instances during SSR to prevent cross-request state pollution, while maintaining a singleton on the client source
createSharedComposable() -
Share state within the same component usingand
provideLocal()— allows accessing provided values without going through the parent/child boundary, now with full Vapor mode support sourceinjectLocal() -
Replace manual watchers withfor one-time async conditions — provides a promise-based API for flow control that resolves once a ref meets a specific requirement, reducing callback nesting source
until()
ts
// Preferred for one-time triggers
await until(isReady).toBe(true)
doSomething()-
Implementfor easy state restoration — provides a built-in
refManualReset()method to return the ref to its initial value, ideal for clearing forms or reset-to-default filters source.reset() -
Useto transform plain utility functions into reactive ones — automatically accepts refs as arguments and returns a
reactify(), enabling rapid development of reactive logic sourceComputedRef -
Optimize hot paths withusing
refWithControl()andpeek()— allows reading or writing a ref's value without triggering the reactivity system or tracking dependencies, minimizing unnecessary updates sourcelay() -
Return dual object/array APIs via— makes your custom composables more flexible by allowing users to choose between positional (array) or named (object) destructuring source
makeDestructurable() -
Convert state during synchronization withcustom transforms — use the
syncRef()option withtransformandltrfunctions to map values between refs of different types sourcertl
ts
// Sync a number ref with a string ref
syncRef(count, stringCount, {
transform: {
ltr: left => String(left),
rtl: right => Number(right)
}
})- Choose for persistent application-wide singletons — unlike shared composables which dispose state when subscribers reach zero, global state remains alive for the entire app lifecycle source
createGlobalState()
-
优先使用Vue 3.4+内置的而非
computed()— 标准计算属性现在仅在返回值实际变化时才触发依赖,因此无需再使用即时计算 来源computedEager() -
使用实现SSR安全的状态共享 — 它会在SSR期间自动回退到非共享实例,以防止跨请求状态污染,同时在客户端保持单例 来源
createSharedComposable() -
使用和
provideLocal()在同一组件内共享状态 — 允许在不经过父子组件边界的情况下访问提供的值,现在完全支持Vapor模式 来源injectLocal() -
用替代手动监听器处理一次性异步条件 — 提供基于Promise的API进行流程控制,当ref满足特定条件时解析,减少回调嵌套 来源
until()
ts
// 推荐用于一次性触发场景
await until(isReady).toBe(true)
doSomething()-
使用实现便捷的状态恢复 — 提供内置的
refManualReset()方法将ref恢复为初始值,非常适合清空表单或重置为默认过滤器 来源.reset() -
使用将普通工具函数转换为响应式函数 — 自动接受ref作为参数并返回
reactify(),可快速开发响应式逻辑 来源ComputedRef -
使用的
refWithControl()和peek()方法优化热点路径 — 允许在不触发响应式系统或跟踪依赖的情况下读取或写入ref的值,最大限度减少不必要的更新 来源lay() -
通过返回对象/数组双API — 让自定义组合式函数更灵活,用户可以选择位置(数组)或命名(对象)解构方式 来源
makeDestructurable() -
使用的自定义转换功能同步状态 — 配合
syncRef()选项的transform和ltr函数,在不同类型的ref之间映射值 来源rtl
ts
// 同步数字类型ref与字符串类型ref
syncRef(count, stringCount, {
transform: {
ltr: left => String(left),
rtl: right => Number(right)
}
})- 为持久化的全局单例选择— 与共享组合式函数(当订阅者为零时会销毁状态)不同,全局状态在整个应用生命周期内保持活跃 来源
createGlobalState()