vue同一页面动态路由切换animate.css动画不重新加载的问题

1、需要在updated生命周期里再重新创建wow示例

updated() {
          new this.$wow.WOW().init({//新建实列
                boxClass: 'wow',//class名字
                animateClass: 'animate__animated',//animateclass动画库类名,和当前animate动画库决定
                offset: 0,//到元素距离触发动画(当默认为0)
                mobile: true,//在移动设备上触发动画(默认为true)
                live: true//对异步加载的内容进行操作(默认为true)
                })
        },

2、公用的每个标签上加上动态的key值,使得虚拟dom重新加载真实dom

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要根据路由的 meta 属性动态切换 animate.css 的效果,可以使用路由守卫结合动态类绑定的方式来实现。下面以 Vue.jsVue Router 为例,演示如何实现: 1. 首先,在路由配置中定义每个路由的 meta 属性,用于指定要应用的 animate.css 的效果类。 ```javascript const routes = [ { path: '/', component: Home, meta: { animation: 'animate__fadeIn' } }, { path: '/about', component: About, meta: { animation: 'animate__slideInRight' } }, // 其他路由配置... ]; ``` 在上面的例子中,我们为根路径 `'/'` 的路由配置了 `'animate__fadeIn'` 的效果类,而对于 `'/about'` 路由则配置了 `'animate__slideInRight'` 的效果类。你可以根据需要自定义不同的效果类。 2. 在 Vue 组件中的导航守卫中根据路由的 meta 属性动态切换 animate.css 的效果类。 ```javascript // 在 Vue 组件中的路由守卫中动态切换动画效果 export default { // ... beforeRouteEnter(to, from, next) { next(vm => { // 通过 vm.$route.meta.animation 获取当前路由的 animate.css 效果类 const animation = vm.$route.meta.animation; // 获取要切换的元素,并添加动画效果类 const element = document.getElementById('yourElementId'); element.classList.add('animate__animated', animation); }); }, beforeRouteLeave(to, from, next) { // 在切换路由前,移除动画效果类 const element = document.getElementById('yourElementId'); element.classList.remove('animate__animated'); next(); }, // ... } ``` 在上述代码中,我们在 `beforeRouteEnter` 导航守卫中获取当前路由的 meta 属性,并将其应用到要切换的元素上。通过 `vm.$route` 可以访问到当前路由的信息,包括其 meta 属性。然后,我们获取要切换的元素,并使用 `classList.add` 方法添加 `'animate__animated'` 和动画效果类。 在 `beforeRouteLeave` 导航守卫中,我们在切换路由前移除动画效果类,以确保下次切换重新应用新的动画效果。 请确保在要切换的元素上设置了唯一的 id,以便通过 `getElementById` 获取到正确的元素。 通过以上步骤,你就可以根据路由的 meta 属性动态切换 animate.css 的效果了。希望对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值