vueuse-integrations-skilld
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesevueuse/vueuse @vueuse/integrations
@vueuse/integrationsvueuse/vueuse @vueuse/integrations
@vueuse/integrationsVersion: 14.2.1 (Feb 2026)
Deps: @vueuse/core@14.2.1, @vueuse/shared@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/core@14.2.1,@vueuse/shared@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 Issues — bug、解决方案、边缘案例 • GitHub讨论 — 问答、模式、实践方案 • 版本发布记录 — 更新日志、破坏性变更、新API
API Changes
API变更
This section documents version-specific API changes — prioritize recent major/minor releases.
-
BREAKING: Requires Vue 3.5+ — v14.x now requires Vue 3.5.0 as a peer dependency for native features like
useTemplateRef -
BREAKING: ESM-only — dropped CommonJS (CJS) build in v13.0.0, now an ESM-only package source
-
BREAKING:dependency —
focus-trapupdated peer dependency range touseFocusTrapin v14.2.0 source^7 || ^8 -
BREAKING:dependency —
universal-cookienow supports and prefersuseCookiesuniversal-cookie^7 || ^8 -
BREAKING:v5 —
change-caseis now compatible withuseChangeCasev5, including internal naming changeschange-case -
DEPRECATED: Alias exports — v14.0.0 deprecated alias exports in favor of original function names for consistency source
-
NEW:option —
watchElementaddeduseSortablein v14.2.0 to auto-reinitialize when target element changes sourcewatchElement -
NEW:—
updateContainerElementsexposeduseFocusTrapin v13.6.0 for dynamic container updates sourceupdateContainerElements -
NEW:option —
serializeraddeduseIDBKeyvalin v13.6.0 for custom data serialization sourceoptions.serializer -
NEW: Component Ref support —can now accept a Vue component instance/ref as the target element since v13.1.0 source
useSortable -
NEW: Thenable—
useAxiosreturns are now thenable, allowinguseAxiosin async contexts sourceawait useAxios(...) -
NEW: Flexible—
executeuseAxioscan now takeexecute()orurlseparately for manual triggers sourceconfig -
NEW:option —
initialDataaddeduseAxiosto provide a default value before the request finishes sourceinitialData -
NEW: Helper functions —,
moveArrayElement, andinsertNodeAtare now exported fromremoveNodesourceuseSortable
Also changed: internal types · options refinement · reactive state consistency · type misalignment fix source
useAsyncValidatoruseJwtuseNProgressuseSortable本节记录特定版本的API变更 — 优先关注近期的大版本/小版本更新。
-
破坏性变更:要求Vue 3.5+ — v14.x版本现在要求Vue 3.5.0作为peer依赖,以支持等原生特性
useTemplateRef -
破坏性变更:仅支持ESM — v13.0.0版本移除了CommonJS(CJS)构建,现在是纯ESM包来源
-
破坏性变更:依赖 — v14.2.0版本中
focus-trap的peer依赖范围更新为useFocusTrap来源^7 || ^8 -
破坏性变更:依赖 —
universal-cookie现在支持并优先使用useCookiesuniversal-cookie版本^7 || ^8 -
破坏性变更:v5 —
change-case现在兼容useChangeCasev5版本,包括内部命名变更change-case -
已废弃:别名导出 — v14.0.0版本废弃了别名导出,改用原始函数名称以保持一致性来源
-
新增:选项 — v14.2.0版本中
watchElement新增useSortable选项,当目标元素变化时自动重新初始化来源watchElement -
新增:— v13.6.0版本中
updateContainerElements暴露了useFocusTrap方法,用于动态更新容器来源updateContainerElements -
新增:选项 — v13.6.0版本中
serializer新增useIDBKeyval选项,支持自定义数据序列化来源options.serializer -
新增:组件Ref支持 — 自v13.1.0版本起,可以接受Vue组件实例/Ref作为目标元素来源
useSortable -
新增:Thenable—
useAxios的返回值现在支持thenable,允许在异步上下文使用useAxios来源await useAxios(...) -
新增:灵活的—
execute的useAxios方法现在可以单独传入execute()或url以手动触发请求来源config -
新增:选项 —
initialData新增useAxios选项,用于在请求完成前提供默认值来源initialData -
新增:辅助函数 —、
moveArrayElement和insertNodeAt现在从removeNode中导出来源useSortable
其他变更:内部类型优化 · 选项细化 · 响应式状态一致性优化 · 类型不匹配修复来源
useAsyncValidatoruseJwtuseNProgressuseSortableBest Practices
最佳实践
- Import functions from submodules to maximize tree-shaking efficiency and reduce the final bundle size source
ts
// Preferred
import { useAxios } from '@vueuse/integrations/useAxios'
// Avoid
import { useAxios } from '@vueuse/integrations'- Await directly for one-off requests as the return value is thenable, simplifying promise handling source
useAxios()
ts
const { data, error } = await useAxios('/api/posts')- Enable in
resetOnExecute: trueoptions to clear stale data automatically when a new request is triggered sourceuseAxios
ts
const { execute } = useAxios('/api/data', { method: 'GET' }, { resetOnExecute: true })- Explicitly import in Nuxt 3 environments to avoid name collisions with Nuxt's built-in
useCookiescomposable sourceuseCookie
ts
import { useCookies } from '@vueuse/integrations/useCookies'- Use with
autoUpdateDependencies: trueto automatically track and update dependencies for any cookie names accessed viauseCookiessource.get()
ts
const { get } = useCookies(['initial'], { autoUpdateDependencies: true })- Enable the option in
watchElement: trueto automatically reinitialize the instance when the target element changes (e.g., withuseSortable) sourcev-if
ts
useSortable(el, list, { watchElement: true })- Wrap post-update logic in after calling
nextTick()inmoveArrayElementto ensure the DOM update has fully finished sourceuseSortable
ts
useSortable(el, list, {
onUpdate: (e) => {
moveArrayElement(list, e.oldIndex, e.newIndex)
nextTick(() => { /* perform post-move logic */ })
}
})- Use before calling
nextTick()inactivate()when dealing with conditionally rendered (useFocusTrap) elements to ensure they exist in the DOM sourcev-if
ts
async function openModal() {
show.value = true
await nextTick()
activate()
}- Prefer the component over the manual composable for automatic activation on mount and cleanup on unmount source
UseFocusTrap
vue
<UseFocusTrap v-if="show" :options="{ immediate: true }">
<div class="modal">...</div>
</UseFocusTrap>- Await the method returned by
.set()to ensure that the IndexedDB transaction is fully committed before proceeding sourceuseIDBKeyval
ts
const count = useIDBKeyval('my-count', 0)
await count.set(10)- 从子模块导入函数以最大化tree-shaking效率,减小最终打包体积来源
ts
// 推荐写法
import { useAxios } from '@vueuse/integrations/useAxios'
// 不推荐写法
import { useAxios } from '@vueuse/integrations'- 直接处理一次性请求,因为返回值支持thenable,简化Promise处理来源
await useAxios()
ts
const { data, error } = await useAxios('/api/posts')- 在选项中启用
useAxios,以在触发新请求时自动清除过期数据来源resetOnExecute: true
ts
const { execute } = useAxios('/api/data', { method: 'GET' }, { resetOnExecute: true })- 在Nuxt 3环境中显式导入,避免与Nuxt内置的
useCookies组合式函数命名冲突来源useCookie
ts
import { useCookies } from '@vueuse/integrations/useCookies'- 为启用
useCookies,以自动跟踪并更新通过autoUpdateDependencies: true访问的所有Cookie名称的依赖来源.get()
ts
const { get } = useCookies(['initial'], { autoUpdateDependencies: true })- 在中启用
useSortable选项,当目标元素变化时(例如使用watchElement: true)自动重新初始化实例来源v-if
ts
useSortable(el, list, { watchElement: true })- 在中调用
useSortable后,将更新后逻辑包裹在moveArrayElement中,确保DOM更新完全完成来源nextTick()
ts
useSortable(el, list, {
onUpdate: (e) => {
moveArrayElement(list, e.oldIndex, e.newIndex)
nextTick(() => { /* 执行移动后的逻辑 */ })
}
})- 当处理条件渲染()的元素时,在调用
v-if的useFocusTrap前使用activate(),确保元素已存在于DOM中来源nextTick()
ts
async function openModal() {
show.value = true
await nextTick()
activate()
}- 优先使用组件而非手动调用组合式函数,以实现挂载时自动激活、卸载时自动清理来源
UseFocusTrap
vue
<UseFocusTrap v-if="show" :options="{ immediate: true }">
<div class="modal">...</div>
</UseFocusTrap>- 调用返回的
useIDBKeyval方法时使用.set(),确保IndexedDB事务完全提交后再继续执行来源await
ts
const count = useIDBKeyval('my-count', 0)
await count.set(10)