vueuse-motion-skilld
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesevueuse/motion @vueuse/motion
@vueuse/motionvueuse/motion @vueuse/motion
@vueuse/motionVersion: 3.0.3 (Mar 2025)
Deps: @vueuse/core@^13.0.0, @vueuse/shared@^13.0.0, defu@^6.1.4, framesync@^6.1.2, popmotion@^11.0.5, style-value-types@^5.1.2
Tags: beta: 2.0.0-beta.29 (May 2023), latest: 3.0.3 (Mar 2025)
References: Docs — API reference, guides • GitHub Issues — bugs, workarounds, edge cases • Releases — changelog, breaking changes, new APIs
版本:3.0.3(2025年3月)
依赖:@vueuse/core@^13.0.0、@vueuse/shared@^13.0.0、defu@^6.1.4、framesync@^6.1.2、popmotion@^11.0.5、style-value-types@^5.1.2
标签:beta: 2.0.0-beta.29(2023年5月)、latest: 3.0.3(2025年3月)
参考文档:文档 —— API参考、使用指南 • GitHub Issues —— 问题反馈、解决方案、边缘场景 • 版本发布记录 —— 更新日志、破坏性变更、新API
API Changes
API变更
This section documents version-specific API changes — prioritize recent major/minor releases.
-
BREAKING: ESM-only —v3.0.0 dropped CommonJS (CJS) support, the package is now ESM-only source
@vueuse/motion -
NEW: VueUse v13 support — updated dependencies to support the latest VueUse features in v3.0.0 source
-
NEW:component — declarative component for animations, offering better SSR and MDC support since v2.2.0 source
<Motion> -
NEW:component — renderless component introduced in v2.2.0 to apply motion configurations to all child elements source
<MotionGroup> -
NEW:and
durationshorthand props — support for setting transition timing directly on elements/components since v2.2.0 sourcedelay -
BREAKING: Drop Vue 2 support — v2.0.0 and above exclusively support Vue 3 source
-
NEW: Full SSR support — significantly improved server-side rendering compatibility for both components and directives in v2.0.0 source
-
NEW: kebab-case directive support —and other directive variants now support kebab-case since v2.1.0 source
v-motion-initial -
NEW:export — this composable is now exported for manual feature registration since v2.2.6 source
useMotionFeatures -
NEW:dynamic keys — support for dynamic variant keys when calling
useMotionand other methods since v2.1.0 source.apply() -
NEW:and
reactive-style— specialized composables for direct style and transform manipulation since v2.0.0 sourcereactive-transform -
NEW:types — enhanced TypeScript definitions for the main Vue plugin in v2.2.5 source
MotionPlugin -
BREAKING:triggers — fixed in v2.2.0 to trigger after each property animation completes instead of only once source
onComplete -
NEW:directive bindings — directives now unref initial bindings, supporting refs within objects since v2.0.0 source
unref
Also changed: variant new v2.0.0 · documentation update v2.2.0 · mutation fix v2.2.0 · dynamic keys v2.1.0 · internal updates v2.0.0
visibilityOnceuseSpringpresetuseMotionsuseMotionVariants本节记录了特定版本的API变更——优先关注近期的主要/次要版本更新。
-
破坏性变更:仅支持ESM ——v3.0.0 移除了对CommonJS (CJS)的支持,当前包仅支持ESM 来源
@vueuse/motion -
新增:支持VueUse v13 —— v3.0.0中更新了依赖以支持VueUse的最新特性 来源
-
新增:组件 —— 声明式动画组件,自v2.2.0起提供更好的SSR和MDC支持 来源
<Motion> -
新增:组件 —— 自v2.2.0起引入的无渲染组件,用于为所有子元素应用动画配置 来源
<MotionGroup> -
新增:和
duration简写属性 —— 自v2.2.0起支持直接在元素/组件上设置过渡时间 来源delay -
破坏性变更:移除Vue 2支持 —— v2.0.0及以上版本仅支持Vue 3 来源
-
新增:完整SSR支持 —— v2.0.0中显著提升了组件和指令的服务端渲染兼容性 来源
-
新增:短横线命名法指令支持 —— 自v2.1.0起,及其他指令变体支持短横线命名法 来源
v-motion-initial -
新增:导出—— 自v2.2.6起,该组合式函数被导出用于手动注册特性 来源
useMotionFeatures -
新增:动态键 —— 自v2.1.0起,调用
useMotion及其他方法时支持动态变体键 来源.apply() -
新增:和
reactive-style—— 自v2.0.0起新增的专用组合式函数,用于直接操作样式和变换 来源reactive-transform -
新增:类型定义 —— v2.2.5中增强了主Vue插件的TypeScript类型定义 来源
MotionPlugin -
破坏性变更:触发时机 —— v2.2.0中修复为在每个属性动画完成后触发,而非仅触发一次 来源
onComplete -
新增:指令绑定支持—— 自v2.0.0起,指令现在支持对初始绑定进行unref,支持对象内的refs 来源
unref
其他变更: 变体新增于v2.0.0 · 文档更新于v2.2.0 · 修改修复于v2.2.0 · 动态键支持于v2.1.0 · 内部更新于v2.0.0
visibilityOnceuseSpringpresetuseMotionsuseMotionVariantsBest Practices
最佳实践
- Avoid deconstructing at the top level of
useMotions()because properties are registered after the script execution; access them via the returned object within methods or hooks to ensure reactivity sourcesetup
ts
// Preferred
const motions = useMotions()
const play = () => motions.myElement?.variant.value = 'play'
// Avoid
const { myElement } = useMotions()-
Use camelCase for visibility variants in Nuxt 3 templates (e.g.,) rather than kebab-case (
visibleOnce) to ensure proper directive resolution and avoid warnings sourcevisible-once -
Prefer thecomponent over the
<Motion>directive for projects requiring robust SSR, as it handles initial state style injection more reliably for SEO and UX sourcev-motion -
Define custom directives in theconfiguration to create reusable animation presets that can be applied consistently via
MotionPluginacross the application sourcev-motion-[name] -
Useto apply a single animation configuration or preset to multiple child elements, significantly reducing template boilerplate and improving maintainability source
<MotionGroup> -
Map thehelper from the motion instance to the Vue
leaveelement's<transition>event to perform manual and synchronized exit animations on elements source@leave
ts
const { leave } = useMotion(target, { leave: { opacity: 0 } })
// In template
// <transition @leave="(el, done) => leave(done)">-
Always specify anvariant containing all properties that will be animated to prevent unexpected layout shifts and ensure smooth transitions from a known base state source
initial -
Utilizewith
useSpringfor high-performance, frame-rate independent animations that require physical continuity, such as for interactive gestures sourceuseMotionProperties -
In Nuxt applications, useto define global custom directives, ensuring they are properly initialized during both client and server rendering source
runtimeConfig.public.motion.directives -
Pass a reactive reference as theto
targetto allow the motion instance to automatically track and apply the current variant to new elements as they are updated sourceuseMotion
- 避免在的顶层解构
setup,因为属性是在脚本执行后才注册的;应在方法或钩子中通过返回的对象访问它们,以确保响应式 来源useMotions()
ts
// 推荐写法
const motions = useMotions()
const play = () => motions.myElement?.variant.value = 'play'
// 避免写法
const { myElement } = useMotions()-
在Nuxt 3模板中对可见性变体使用驼峰命名法(如)而非短横线命名法(
visibleOnce),以确保指令正确解析并避免警告 来源visible-once -
对于需要可靠SSR的项目,优先使用组件而非
<Motion>指令,因为它能更可靠地处理初始状态样式注入,利于SEO和用户体验 来源v-motion -
在配置中定义自定义指令,创建可复用的动画预设,可通过
MotionPlugin在整个应用中一致地应用 来源v-motion-[name] -
使用为多个子元素应用单一动画配置或预设,显著减少模板冗余并提升可维护性 来源
<MotionGroup> -
将motion实例中的辅助函数映射到Vue
leave元素的<transition>事件,以实现元素的手动同步退出动画 来源@leave
ts
const { leave } = useMotion(target, { leave: { opacity: 0 } })
// 在模板中
// <transition @leave="(el, done) => leave(done)">-
始终指定包含所有将被动画化属性的变体,以防止意外的布局偏移并确保从已知基础状态开始的平滑过渡 来源
initial -
结合和
useSpring实现高性能、帧率无关的动画,这类动画需要物理连续性,例如交互式手势场景 来源useMotionProperties -
在Nuxt应用中,使用定义全局自定义指令,确保它们在客户端和服务端渲染期间都能正确初始化 来源
runtimeConfig.public.motion.directives -
向传入响应式引用作为
useMotion,使motion实例能够自动跟踪并将当前变体应用于更新后的新元素 来源target