motion-v-skilld
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesemotiondivision/motion-vue motion-v
motion-vmotiondivision/motion-vue motion-v
motion-vVersion: 2.0.0-beta.4 (Feb 2026)
Deps: framer-motion@^12.29.2, hey-listen@^1.0.8, motion-dom@^12.29.2, motion-utils@^12.29.2
Tags: latest: 2.0.0-beta.4 (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
**版本:**2.0.0-beta.4(2026年2月)
**依赖:**framer-motion@^12.29.2, hey-listen@^1.0.8, motion-dom@^12.29.2, motion-utils@^12.29.2
**标签:**latest: 2.0.0-beta.4(2026年2月)
参考文档:文档 — API参考、使用指南 • GitHub Issues — 问题反馈、解决方案、边缘场景 • GitHub Discussions — 问答、模式参考、使用示例 • 版本发布记录 — 更新日志、破坏性变更、新API
API Changes
API变更
This section documents version-specific API changes — prioritize recent major/minor releases.
-
BREAKING:,
focus,hover,pressshorthand props — removed in v2.0.0-beta.1. UseinView,whileFocus,whileHover, andwhilePressfor animations, and full event handlers (e.g.whileInView,@hoverStart) for logic source@pressStart -
NEW:directive — new in v2.0.0-beta.1, enables declarative animations on any element without requiring a
v-motioncomponent wrapper source<motion> -
BREAKING: ESM-only — v2.0.0-beta.1 dropped CommonJS support. The package now only ships ESM () exports source
.mjs -
NEW:— new in v2.0.0-beta.1, a Vue plugin for global
MotionPluginand custom preset directive registrationv-motion -
NEW:— new in v2.0.0-beta.1, allows creating reusable animation directives with baked-in motion options
createPresetDirective() -
BREAKING:lazy discovery — v2.0.0-beta.1 refactored to use
AnimatePresenceattribute for lazy discovery instead of eager registration sourcedata-ap -
DEPRECATED:and
staggerChildren— deprecated in v1.4.0 in favor of using thestaggerDirectionutility within thestagger()prop sourcetransition -
NEW:utility — correctly handles staggering for newly-entering siblings alongside existing ones since v1.7.0 source
stagger() -
NEW:output maps — supports providing multiple output value maps for complex coordinate transformations since v1.9.0 source
useTransform -
NEW:auto-scrolling — supports automatic parent container scrolling when a
Reorderis dragged to the edges since v1.8.0 sourceReorder.Item -
NEW:VueInstance support —
useScrollandcontaineroptions now accepttarget(ref to component) since v1.6.0 sourceVueInstance -
NEW:
useInViewoption — now acceptsrootfor dynamic root element assignment since v1.6.0 sourceMaybeRef -
NEW:direct children — supports multiple direct
AnimatePresencecomponents as children since v1.10.0 sourcemotion -
NEW:— exported as a standalone utility function for time-based animation delays since v1.6.0 source
delayInMs
Also changed: reactive update fix (v1.2.1) · at relative start (v1.3.0) · custom prop fix (v1.3.0) · exported (v2.0.0-beta.1) · tree-shaking architecture (v2.0.0-beta.1)
useTransformsequenceAnimatePresencemotionGlobalConfigFeatureBundle本部分记录各版本专属的API变更,请优先关注近期的主要/次要版本更新。
-
破坏性变更:,
focus,hover,press简写属性 — 在v2.0.0-beta.1中移除。动画效果请使用inView、whileFocus、whileHover和whilePress,逻辑处理请使用完整事件处理器(如whileInView、@hoverStart)来源@pressStart -
新增:指令 — v2.0.0-beta.1新增,无需使用
v-motion组件包裹,即可为任意元素添加声明式动画来源<motion> -
破坏性变更:仅支持ESM — v2.0.0-beta.1移除了CommonJS支持。该包现在仅提供ESM(.mjs)格式的导出来源
-
新增:— v2.0.0-beta.1新增,是一个Vue插件,用于全局注册
MotionPlugin和自定义预设指令v-motion -
新增:— v2.0.0-beta.1新增,允许创建包含内置动画选项的可复用动画指令
createPresetDirective() -
破坏性变更:惰性发现 — v2.0.0-beta.1重构为使用
AnimatePresence属性进行惰性发现,而非提前注册来源data-ap -
已弃用:和
staggerChildren— 在v1.4.0中被弃用,建议在staggerDirection属性中使用transition工具函数替代来源stagger() -
新增:工具函数 — 自v1.7.0起,可正确处理新进入的兄弟元素与现有元素的交错动画来源
stagger() -
新增:输出映射 — 自v1.9.0起,支持提供多个输出值映射以实现复杂的坐标转换来源
useTransform -
新增:自动滚动 — 自v1.8.0起,当
Reorder被拖拽到容器边缘时,支持父容器自动滚动来源Reorder.Item -
新增:Vue实例支持 — 自v1.6.0起,
useScroll和container选项现在接受target(组件的ref引用)来源VueInstance -
新增:
useInView选项 — 自v1.6.0起,支持接受root以动态设置根元素来源MaybeRef -
新增:直接子元素 — 自v1.10.0起,支持多个直接
AnimatePresence组件作为子元素来源motion -
新增:— 自v1.6.0起,作为独立的工具函数导出,用于基于时间的动画延迟来源
delayInMs
其他变更:响应式更新修复(v1.2.1)· 相对起始位置(v1.3.0)· 自定义属性修复(v1.3.0)· 导出(v2.0.0-beta.1)· 摇树优化架构(v2.0.0-beta.1)
useTransformsequenceAnimatePresencemotionGlobalConfigFeatureBundleBest Practices
最佳实践
- Create motion-supercharged components using outside of the template to avoid re-creating the component on every render, which would break animations source
motion.create()
ts
// Preferred
const MotionComponent = motion.create(Component)
// Avoid - re-created every render
<component :is="motion.create(Component)" />- Use s in the
MotionValueprop to animate values outside of the Vue render cycle, significantly improving performance by avoiding frequent re-renders sourcestyle
vue
<script setup>
const x = useMotionValue(0)
</script>
<template>
<motion.div :style="{ x }" />
</template>- Reduce initial bundle size from ~34kb to ~6kb by using the component paired with
mto load features synchronously or asynchronously only when needed sourceLazyMotion
vue
<template>
<LazyMotion :features="domAnimation">
<m.div :animate="{ opacity: 1 }" />
</LazyMotion>
</template>-
Enable theprop on
strictduring development to catch accidental usage of the fullLazyMotioncomponent, which would negate the bundle size benefits of lazy loading sourcemotion -
Centralize animation settings like global transitions and site-widepolicies using
reducedMotionto ensure consistent behavior across all child components sourceMotionConfig -
(experimental) Apply declarative animations directly to any standard HTML/SVG element using thedirective in v2.0.0-beta.1+ without needing to wrap elements in a
v-motioncomponent source<motion> -
Ensurechildren have unique, stable
AnimatePresenceprops and are direct children of the component to correctly track their removal for exit animations sourcekey -
Synchronize layout animations across unrelated components (those that don't share a parent-child relationship but affect each other's layout) by wrapping them in asource
LayoutGroup -
Prevent visual distortion of child elements during parent layout animations by applying theprop to the immediate children as well, enabling scale correction source
layout -
Mark scrollable ancestors withand fixed-position ancestors with
layoutScrollto ensure Motion correctly accounts for scroll offsets during layout measurements sourcelayoutRoot
- 在模板外部使用创建增强动画的组件,避免每次渲染时重新创建组件,否则会导致动画失效来源
motion.create()
ts
// Preferred
const MotionComponent = motion.create(Component)
// Avoid - re-created every render
<component :is="motion.create(Component)" />- 在属性中使用
style来在Vue渲染周期外执行动画,通过避免频繁重渲染显著提升性能来源MotionValue
vue
<script setup>
const x = useMotionValue(0)
</script>
<template>
<motion.div :style="{ x }" />
</template>- 通过搭配使用组件和
m,将初始包体积从约34kb减小到约6kb,实现按需同步或异步加载所需功能来源LazyMotion
vue
<template>
<LazyMotion :features="domAnimation">
<m.div :animate="{ opacity: 1 }" />
</LazyMotion>
</template>-
在开发阶段为启用
LazyMotion属性,防止意外使用完整的strict组件,否则会抵消懒加载带来的包体积优化效果来源motion -
使用集中管理动画设置,比如全局过渡效果和站点级
MotionConfig策略,确保所有子组件的行为一致来源reducedMotion -
(实验性)在v2.0.0-beta.1及以上版本中,可使用指令直接为任意标准HTML/SVG元素添加声明式动画,无需将元素包裹在
v-motion组件中来源<motion> -
确保的子元素拥有唯一且稳定的
AnimatePresence属性,并且是该组件的直接子元素,这样才能正确跟踪元素的移除并执行退出动画来源key -
通过将不相关的组件(无父子关系但会互相影响布局的组件)包裹在中,实现跨组件的布局动画同步来源
LayoutGroup -
在父组件执行布局动画时,为直接子元素添加属性以启用缩放校正,防止子元素出现视觉变形来源
layout -
为可滚动的祖先元素添加属性,为固定定位的祖先元素添加
layoutScroll属性,确保Motion在测量布局时正确考虑滚动偏移来源layoutRoot