vueuse-components-skilld
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesevueuse/vueuse @vueuse/components
@vueuse/componentsvueuse/vueuse @vueuse/components
@vueuse/componentsVersion: 14.2.1 (Feb 2026)
Deps: @vueuse/shared@14.2.1, @vueuse/core@14.2.1
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月)
依赖:@vueuse/shared@14.2.1,@vueuse/core@14.2.1
**标签:**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 for — prioritize recent major/minor releases.
@vueuse/components-
BREAKING:v14+ requires Vue 3.5+, following core library requirements source
@vueuse/components -
BREAKING: Renderless components refactored for consistency in v14.0.0. Components likeand
OnClickOutsidenow use anOnLongPressprop for configuration andoptionsemit for actions source@trigger -
BREAKING: ESM-only package — CJS build has been dropped since v13.0.0 source
-
DEPRECATED:is deprecated in favor of the lowercase
VOnClickOutsidedirective sourcevOnClickOutside -
DEPRECATED:is deprecated in favor of the lowercase
VOnLongPressdirective sourcevOnLongPress -
NEW:supports
UseDraggableandautoScrolloptions for constrained dragging in v14.2.0 sourcerestrictInView -
NEW:supports
UseDraggableandstorageKeyprops for persistent element position sourcestorageType -
NEW:directive added for listening to keyboard events directly on elements
vOnKeyStroke -
NEW:default slot data now includes
UseIdleandpausemethods viaresumeimplementation sourceStoppable -
NEW:supports reactive
vInfiniteScrolloption in v14.1.0 sourcecanLoadMore -
NEW:added
UseElementVisibilityoption in v14.1.0 sourceinitialValue -
NEW:supports tracking inline-level elements in v14.1.0 source
UseMouseInElement -
NEW:now supports reactive
vIntersectionObserveroption in v14.2.0 sourcerootMargin -
NEW:emits
UseOffsetPagination,page-change, andpage-size-changeeventspage-count-change
Also changed: custom interpolators · new function · failSilently · execute result · custom units
useTransitionrefManualResettryOnScopeDisposeuseAsyncStateuseTimeAgoIntl本节记录各版本的API变更信息——优先参考近期的大版本/小版本更新。
@vueuse/components-
破坏性变更:v14+要求Vue 3.5+,遵循核心库的要求 来源
@vueuse/components -
**破坏性变更:**无渲染组件在v14.0.0中进行了重构以保持一致性。和
OnClickOutside等组件现在使用OnLongPress属性进行配置,通过options事件触发操作 来源@trigger -
**破坏性变更:**仅支持ESM的包——自v13.0.0起已移除CJS构建版本 来源
-
已废弃:已被废弃,推荐使用小写形式的
VOnClickOutside指令 来源vOnClickOutside -
已废弃:已被废弃,推荐使用小写形式的
VOnLongPress指令 来源vOnLongPress -
新增:在v14.2.0中支持
UseDraggable和autoScroll选项,用于约束拖拽范围 来源restrictInView -
新增:支持
UseDraggable和storageKey属性,用于持久化元素位置 来源storageType -
**新增:**添加了指令,用于直接在元素上监听键盘事件
vOnKeyStroke -
新增:的默认插槽数据现在通过
UseIdle实现包含Stoppable和pause方法 来源resume -
新增:在v14.1.0中支持响应式的
vInfiniteScroll选项 来源canLoadMore -
新增:在v14.1.0中添加了
UseElementVisibility选项 来源initialValue -
新增:在v14.1.0中支持跟踪内联级元素 来源
UseMouseInElement -
新增:在v14.2.0中现在支持响应式的
vIntersectionObserver选项 来源rootMargin -
新增:触发
UseOffsetPagination、page-change和page-size-change事件page-count-change
其他变更:自定义插值器 · 新函数 · 静默失败 · 执行结果 · 自定义单位
useTransitionrefManualResettryOnScopeDisposeuseAsyncStateuseTimeAgoIntlBest Practices
最佳实践
-
Use theand
storage-keyprops on thestorage-typecomponent to automatically persist element position in<UseDraggable>orlocalStorageacross sessions sourcesessionStorage -
Utilize theoption in
ignore(component or directive) to pass an array of refs or CSS selectors for elements that should not trigger the handler, essential for complex UIs like nested modals sourceOnClickOutside -
Always provideand
#loadingslots in#errorto prevent layout shifts and handle broken images gracefully, rather than managing loading states manually in the script source<UseImage> -
Preferover extracting small, repeated UI fragments into separate files to maintain access to local scope variables and avoid tedious prop/emit definitions source
createReusableTemplate -
Provide a generic type toto enable full TypeScript support and IDE autocompletion for data passed between
createReusableTemplate<T>()andDefineTemplatesourceReuseTemplate -
Useto call complex UI elements like modals or dialogs as promises, keeping the UI definition in the template while maintaining programmatic control and clean async/await flows source
createTemplatePromise -
Configuredirectives like
@vueuse/componentsorv-on-click-outsideusing thev-on-long-pressarray syntax for clean, inline logic without needing a separate setup variable for options source[handler, options]
vue
<div v-if="modal" v-on-click-outside="[closeModal, { ignore: [ignoreElRef] }]">
Hello World
</div>-
Use thecomponent to handle complex pagination state; it emits clean events (
<UseOffsetPagination>,page-change) that are more idiomatic and easier to wire up in templates than manually watching refs sourcepage-size-change -
Setin
detectIframe: trueoptions when building global navigation or modals to ensure they close when the user clicks inside an iframe, an edge case often missed in manual implementations sourceonClickOutside -
Utilize theprop on renderable components like
asor<UseElementBounding>to render them as semantically correct HTML elements (e.g.,<UseFullscreen>,section) instead of the defaultnavsourcediv
-
在组件上使用
<UseDraggable>和storage-key属性,可在storage-type或localStorage中自动持久化元素位置,跨会话保留 来源sessionStorage -
在(组件或指令)中使用
OnClickOutside选项,传入ref数组或CSS选择器,指定不应触发处理函数的元素,这对于嵌套模态框等复杂UI至关重要 来源ignore -
始终在中提供
<UseImage>和#loading插槽,以防止布局偏移并优雅地处理图片加载失败的情况,而不是在脚本中手动管理加载状态 来源#error -
优先使用,而不是将小型重复UI片段提取到单独文件中,这样可以保持对局部作用域变量的访问,避免繁琐的属性/事件定义 来源
createReusableTemplate -
为提供泛型类型,以启用完整的TypeScript支持和IDE自动补全,用于在
createReusableTemplate<T>()和DefineTemplate之间传递的数据 来源ReuseTemplate -
使用将模态框或对话框等复杂UI元素作为Promise调用,将UI定义保留在模板中,同时保持程序化控制和清晰的async/await流程 来源
createTemplatePromise -
使用数组语法配置
[handler, options]指令,如@vueuse/components或v-on-click-outside,实现简洁的内联逻辑,无需为选项单独设置变量 来源v-on-long-press
vue
<div v-if="modal" v-on-click-outside="[closeModal, { ignore: [ignoreElRef] }]">
Hello World
</div>-
使用组件处理复杂的分页状态;它触发清晰的事件(
<UseOffsetPagination>、page-change),比手动监听ref更符合Vue的惯用写法,也更容易在模板中连接逻辑 来源page-size-change -
当构建全局导航或模态框时,在选项中设置
onClickOutside,确保用户点击iframe内部时导航或模态框能关闭,这是手动实现中常被忽略的边界情况 来源detectIframe: true -
在或
<UseElementBounding>等可渲染组件上使用<UseFullscreen>属性,将它们渲染为语义正确的HTML元素(如as、section),而不是默认的nav来源div