vueuse-core-skilld
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesevueuse/vueuse @vueuse/core
@vueuse/corevueuse/vueuse @vueuse/core
@vueuse/coreVersion: 14.2.1 (Feb 2026)
Deps: @types/web-bluetooth@^0.0.21, @vueuse/metadata@14.2.1, @vueuse/shared@14.2.1
Tags: vue2: 2.0.35 (Jul 2020), vue3: 3.0.35 (Jul 2020), demi: 4.0.0-alpha.0 (Jul 2020), 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月)
依赖:@types/web-bluetooth@^0.0.21, @vueuse/metadata@14.2.1, @vueuse/shared@14.2.1
**标签:**vue2: 2.0.35(2020年7月), vue3: 3.0.35(2020年7月), demi: 4.0.0-alpha.0(2020年7月), alpha: 14.0.0-alpha.3(2025年9月), beta: 14.0.0-beta.1(2025年9月), latest: 14.2.1(2026年2月)
参考链接:文档 — API参考、指南 • GitHub问题 — bug、解决方案、边缘情况 • GitHub讨论 — 问答、模式、实践方案 • 版本发布记录 — 更新日志、破坏性变更、新API
API Changes
API变更
This section documents version-specific API changes — prioritize recent major/minor releases.
-
BREAKING:— default
computedAsyncchanged fromflushtoprein v14.0.0; code relying on deferred evaluation now runs synchronously by default sourcesync -
BREAKING:— aligned with traditional throttle behavior in v14.0.0 (trailing call behavior changed); previously called on both leading and trailing by default, verify options match expected behavior source
useThrottleFn -
BREAKING:— on client side, now returns only the shared composable (single value) instead of a tuple/object in v14.0.0 source
createSharedComposable -
BREAKING:— in v13.7.0,
useAsyncStateis now the defaultglobalThis.reportErrorhandler; previously errors were silently swallowed if no handler was provided sourceonError -
BREAKING: CJS build dropped in v13.0.0 —is now ESM-only;
@vueuse/coreno longer works sourcerequire('@vueuse/core') -
BREAKING: Vue 3.5 is now required as a minimum peer dependency since v14.0.0 source
-
DEPRECATED:— will be removed in a future version; Vue 3.5 native
watchPausablenow returnswatch()directly; use{ stop, pause, resume }instead sourceconst { pause, resume } = watch(src, cb) -
DEPRECATED:— will be removed in a future version; Vue 3.4+
computedEagerno longer triggers dependents when the value does not change, making this unnecessary sourcecomputed() -
DEPRECATED:— deprecated in v13.6.0; use Vue's built-in
templateRef(key)instead sourceuseTemplateRef() -
DEPRECATED:— use the new
executeTransition()function instead;transition()option also deprecated, useUseTransitionOptions.transitionsourceeasing -
DEPRECATED:— was an alias for
breakpointsVuetify; now deprecated, explicitly usebreakpointsVuetifyV2orbreakpointsVuetifyV2sourcebreakpointsVuetifyV3 -
DEPRECATED:— alias for
asyncComputed, removed from v14 alias exports; import ascomputedAsyncsourcecomputedAsync -
NEW:— added in v14.0.0; creates a ref with a
refManualReset(defaultValue)method that restores the initial value source.reset() -
NEW:/
useCssSupports(property, value)— added in v14.2.0; reactive wrapper foruseCssSupports(conditionText)sourceCSS.supports() -
NEW:— added in v13.7.0; Intl-based time-ago formatting using
useTimeAgoIntl(time, options), supports custom units sourceIntl.RelativeTimeFormat -
NEW:— added in v14.0.0 as the non-deprecated replacement for
transition(source, from, to, options); also addsexecuteTransitionoption for custom interpolator functions sourceinterpolation -
NEW:interface +
ConfigurableScheduleroption — added in v14.2.0 to timed composables (scheduler,useCountdown,useNow,useTimestamp,useTimeAgo,useTimeAgoIntl,useElementByPoint,useMemory); replaces deprecated per-composableuseVibrate/intervaloptions sourceimmediate -
NEW:— now implements
useIdleinterface (v14.0.0), returnsStoppablein addition to previous return values source{ pause, resume, stop }
Also changed: rootMargin is now reactive (v14.2.0) · gains option (v14.1.0) and inherits reactive (v14.2.0) · gains function (v14.1.0) · gains option (v13.4.0) · gains option (v13.4.0) · now returns (v14.0.0) · gains option and Promise return (v13.6.0) · initial value can now be a ref (v14.0.0) · gains option (v14.2.0) · accepts a function (v14.1.0) · exposes method (v13.7.0) · gains auto-scroll with container-restricted dragging (v14.2.0) · gains option (v13.8.0) · can now be a function (v14.0.0) · target can now be a getter function (v14.0.0)
useIntersectionObserveruseElementVisibilityinitialValuerootMarginuseDropZonecheckValidityuseRefHistoryshouldCommituseUrlSearchParamsstringifywatchAtMost{ pause, resume }useStorageAsynconReadyuseAsyncStateuseSortablewatchElementuseWebSocketautoConnect.delayuseClipboardItemsread()useDraggableuseEventSourceserializeronLongPressdelayonClickOutside本节记录各版本特有的API变更 — 优先关注近期的大版本/小版本更新。
-
破坏性变更:— 在v14.0.0版本中,默认的
computedAsync选项从flush改为pre;依赖延迟求值的代码现在默认会同步执行 来源sync -
破坏性变更:— 在v14.0.0版本中对齐了传统节流行为(尾部调用逻辑变更);之前默认同时调用首部和尾部函数,请验证选项是否符合预期行为 来源
useThrottleFn -
破坏性变更:— 在客户端,v14.0.0版本现在仅返回共享的组合式函数(单个值),而非元组/对象 来源
createSharedComposable -
破坏性变更:— 在v13.7.0版本中,
useAsyncState成为默认的globalThis.reportError处理器;之前如果未提供处理器,错误会被静默忽略 来源onError -
**破坏性变更:**v13.0.0版本移除了CJS构建 —现在仅支持ESM;
@vueuse/core不再生效 来源require('@vueuse/core') -
**破坏性变更:**从v14.0.0版本开始,最低peer依赖要求升级为Vue 3.5 来源
-
已废弃:— 会在未来版本移除;Vue 3.5原生
watchPausable现在直接返回watch();请改用{ stop, pause, resume }来源const { pause, resume } = watch(src, cb) -
已废弃:— 会在未来版本移除;Vue 3.4+的
computedEager现在仅在值变化时触发依赖更新,因此该API已无必要 来源computed() -
已废弃:— 在v13.6.0版本中废弃;请改用Vue内置的
templateRef(key)来源useTemplateRef() -
已废弃:— 请改用新的
executeTransition()函数;transition()选项也已废弃,请使用UseTransitionOptions.transition来源easing -
已废弃:— 曾是
breakpointsVuetify的别名;现已废弃,请显式使用breakpointsVuetifyV2或breakpointsVuetifyV2来源breakpointsVuetifyV3 -
已废弃:— 作为
asyncComputed的别名,已从v14版本的别名导出中移除;请直接导入computedAsync来源computedAsync -
新增:— 在v14.0.0版本中添加;创建一个带有
refManualReset(defaultValue)方法的ref,可恢复初始值 来源.reset() -
新增:/
useCssSupports(property, value)— 在v14.2.0版本中添加;useCssSupports(conditionText)的响应式封装 来源CSS.supports() -
新增:— 在v13.7.0版本中添加;基于Intl的相对时间格式化,使用
useTimeAgoIntl(time, options),支持自定义单位 来源Intl.RelativeTimeFormat -
新增:— 在v14.0.0版本中添加,作为
transition(source, from, to, options)的非废弃替代方案;还新增了executeTransition选项支持自定义插值函数 来源interpolation -
新增:接口 +
ConfigurableScheduler选项 — 在v14.2.0版本中添加到定时类组合式函数(scheduler,useCountdown,useNow,useTimestamp,useTimeAgo,useTimeAgoIntl,useElementByPoint,useMemory);替代了每个组合式函数中已废弃的useVibrate/interval选项 来源immediate -
新增:— 现在实现了
useIdle接口(v14.0.0),除原有返回值外,还返回Stoppable来源{ pause, resume, stop }
其他变更:的rootMargin现在支持响应式(v14.2.0) · 新增选项(v14.1.0)并继承了响应式(v14.2.0) · 新增函数(v14.1.0) · 新增选项(v13.4.0) · 新增选项(v13.4.0) · 现在返回(v14.0.0) · 新增选项并返回Promise(v13.6.0) · 的初始值现在可以是ref(v14.0.0) · 新增选项(v14.2.0) · 的支持传入函数(v14.1.0) · 暴露方法(v13.7.0) · 新增容器限制拖拽时的自动滚动功能(v14.2.0) · 新增选项(v13.8.0) · 的现在可以是函数(v14.0.0) · 的目标现在可以是getter函数(v14.0.0)
useIntersectionObserveruseElementVisibilityinitialValuerootMarginuseDropZonecheckValidityuseRefHistoryshouldCommituseUrlSearchParamsstringifywatchAtMost{ pause, resume }useStorageAsynconReadyuseAsyncStateuseSortablewatchElementuseWebSocketautoConnect.delayuseClipboardItemsread()useDraggableuseEventSourceserializeronLongPressdelayonClickOutsideBest Practices
最佳实践
-
Pass reactive getters () as arguments instead of plain refs where possible — VueUse 9+ supports getter arguments, enabling derived reactive values without an intermediate
() => value(e.g.computed) sourceuseTitle(() => isDark.value ? 'Night' : 'Day') -
Wrapcalls in
useFetchfor app-wide config — sets base URL, auth headers, and CORS mode once; individual call sites inherit it without re-specifying options sourcecreateFetch -
Useoption with
eventFilter/throttleFilterinstead of manually wrapping callbacks — applies rate-limiting at the composable level fordebounceFilter,useLocalStorage, and other event-driven composables sourceuseMouse -
Enable(or pass a custom merge function) on
mergeDefaults: truewhen evolving stored object schemas — without it, new default keys areuseStorageif absent from existing storage data sourceundefined -
Usefrom
StorageSerializerswhen the@vueuse/coredefault value isuseStorage— without a serializer hint, the type cannot be inferred and serialization falls back to raw string sourcenull -
Useto share a single composable instance across components — avoids duplicate event listeners and state. Note: in SSR it automatically falls back to a non-shared instance per call to prevent cross-request pollution source
createSharedComposable -
Usewhen a computed value should only update on specific sources, not all its reactive dependencies —
computedWithControlcannot opt out of automatic dependency tracking, butcomputeddecouples the watch source from the getter sourcecomputedWithControl -
Wrap VueUse calls outside component scope withand call
effectScope()for cleanup — not all composables return a stop handle;scope.stop()is the universal escape hatch when composables are used in stores or non-component contexts sourceeffectScope -
Passoption to browser composables like
windoworuseMouseto target iframes or mock globals in tests — all browser API composables accept configurable global dependencies via options sourceuseScroll -
Pass a customto time-based composables (
scheduler,useNow, etc.) to align them withuseCountdownor throttle their update rate — introduced in v14.1.0 / v14.2.0; without it, timed composables run on their own internal interval independent of animation frames sourceuseRafFn
-
尽可能将响应式 getter()作为参数传递,而非普通的ref — VueUse 9+ 支持getter参数,无需中间
() => value即可实现派生响应式值(例如computed) 来源useTitle(() => isDark.value ? '夜间模式' : '日间模式') -
将调用包裹在
useFetch中实现应用级配置 — 一次性设置基础URL、认证头和CORS模式;各个调用站点无需重复指定选项即可继承配置 来源createFetch -
对、
useLocalStorage等事件驱动的组合式函数,使用useMouse选项搭配eventFilter/throttleFilter,而非手动包裹回调 — 在组合式函数层面实现速率限制 来源debounceFilter -
当演进存储对象的 schema 时,在上启用
useStorage(或传入自定义合并函数) — 否则,如果现有存储数据中缺少新的默认键,这些键的值会是mergeDefaults: true来源undefined -
当的默认值为
useStorage时,使用null中的@vueuse/core— 没有序列化器提示的话,类型无法被推断,序列化会回退到原始字符串 来源StorageSerializers -
使用在多个组件间共享单个组合式函数实例 — 避免重复的事件监听器和状态。注意:在SSR中会自动回退为每次调用创建非共享实例,防止跨请求污染 来源
createSharedComposable -
当计算属性仅需在特定源更新,而非所有响应式依赖更新时,使用—
computedWithControl无法退出自动依赖追踪,但computed可以将监听源与getter解耦 来源computedWithControl -
在组件作用域外调用VueUse时,用包裹并调用
effectScope()进行清理 — 并非所有组合式函数都会返回停止句柄;在状态管理或非组件上下文中使用组合式函数时,scope.stop()是通用的解决方案 来源effectScope -
为或
useMouse等浏览器组合式函数传递useScroll选项,以针对iframe或在测试中模拟全局对象 — 所有浏览器API组合式函数都支持通过选项配置全局依赖 来源window -
为基于时间的组合式函数(、
useNow等)传递自定义useCountdown,使其与scheduler对齐或限制更新速率 — 该特性在v14.1.0/v14.2.0版本引入;不设置的话,定时组合式函数会独立于动画帧运行自己的内部定时器 来源useRafFn