SuperAPI AI 工具集

vueuse-motion-skilld

前端与建站

查看项目

更新于 10-16 00:20

技能介绍

用途:为 Vue 3 应用编写、审查或调试基于 @vueuse/motion 的声明式动画代码。该库基于 Popmotion(非 WAAPI),提供三种可互换的使用面:v-motion 指令、<Motion>/<MotionGroup> 组件、useMotion() 组合式函数。

主要能力:指令支持 initial、enter、leave、visible、visibleOnce、hovered、tapped、focused 等变体及 :variants 自定义键,并有 :delay/:duration 简写;MotionPlugin 注册指令、30 个预设指令(如 v-motion-fade)、全局组件及自定义指令。组件适合 SSR/MDC,preset 用 camelCase 名。useMotion 提供 variant、apply、set、stop、leave、isAnimating 等成员,可用 useMotions() 按字符串键访问模板动画。

使用方式:入口 createApp(App).use(MotionPlugin).mount('#app');Nuxt 将 '@vueuse/motion/nuxt' 加入 modules。

限制:仅 Vue 3(vue >=3.0.0);自 v3.0.0 起仅 ESM,无 CommonJS 构建,CJS 项目需迁移或动态 import;依赖 @vueuse/core、@vueuse/shared v13 与 popmotion 11;Nuxt 集成需 @nuxt/kit >=3.13;动画在 window 上运行,SSR 仅渲染初始变体为内联样式。

注意:时长、延迟、repeatDelay 单位为毫秒(JSDoc 误写为秒);initial 应声明所有后续动画键;visible 离开视口会重新应用 initial,visibleOnce 只触发一次;不要在 setup 顶层解构 useMotions();apply 未知键会抛错;事件变体优先级 hovered < focused < tapped;默认过渡按属性选择(x/y/z/rotate/scale 用弹簧,opacity/color 用 300ms 线性补间,数组目标用 800ms 关键帧)。可用 useReducedMotion() 尊重用户偏好。