Blog
首页
文档
收藏
关于
  • 在线转换时间戳 (opens new window)
  • 在线压缩图片 (opens new window)
  • Float-Double转二进制 (opens new window)
  • 文件转Hex字符串 (opens new window)

HiuZing

🍑
首页
文档
收藏
关于
  • 在线转换时间戳 (opens new window)
  • 在线压缩图片 (opens new window)
  • Float-Double转二进制 (opens new window)
  • 文件转Hex字符串 (opens new window)
  • 前端面试题

  • JavaScript

  • Vue2

  • port

  • CSS

  • Node.js

  • JavaScript优化

  • uniapp

  • Mini Program

  • TypeScript

  • 面向对象编程

  • UI组件

  • Plugin

  • Vue3

    • 教程

    • Vue Router

      • API

      • 基础

      • 进阶

        • 导航守卫
        • 过渡动效
          • 单个路由的过渡
          • 基于路由的动态过渡
        • 路由元信息
        • 滚动行为
        • 动态路由
      • 实例

    • API

    • Vuex

    • 实例处理方案

    • 文档

    • 用法

  • 性能优化

  • Axios

  • 状态管理

  • React

  • Mock

  • Icon

  • Template

  • 构建工具

  • 项目规范配置

  • Taro

  • SVG

  • React Native

  • 前端
  • Vue3
  • Vue Router
  • 进阶
HiuZing
2023-03-18
目录

过渡动效

想要在你的路径组件上使用转场,并对导航进行动画处理,你需要使用 v-slot API (opens new window):

<router-view v-slot="{ Component }">
  <transition name="fade">
    <component :is="Component" />
  </transition>
</router-view>
1
2
3
4
5

# 单个路由的过渡

上面的用法会对所有的路由使用相同的过渡。

过渡动效 | 单个路由的过渡 (opens new window)

如果你想让每个路由的组件有不同的过渡,你可以将元信息 (opens new window)和动态的 name 结合在一起,放在<transition> 上:

此处用Animate.css (opens new window)动效

在App.vue中的router-view添加动效

<router-view #default="{route,Component}">
    <transition  :enter-active-class="`animate__animated ${route.meta.transition}`">
        <component :is="Component"></component>
	</transition>
</router-view>
1
2
3
4
5

在route/index.ts

// 元信息定义类型
declare module 'vue-router'{
     interface RouteMeta {
        title:string,
        transition:string,
     }
}
 
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: () => import('@/views/Login.vue'),
      meta:{
         title:"登录页面",
         transition:"animate__fadeInUp",
      }
    },
    {
      path: '/index',
      component: () => import('@/views/Index.vue'),
      meta:{
         title:"首页!!!",
         transition:"animate__bounceIn",
      }
    }
  ]
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# 基于路由的动态过渡

根据目标路由和当前路由之间的关系,动态地确定使用的过渡。使用和刚才非常相似的片段:

<router-view v-slot="{ Component, route }">
    <transition name="fade-transform" mode="out-in">
        <keep-alive>
        <component :is="Component" :key="route.path"/>
            </keep-alive>
	</transition>
</router-view>
1
2
3
4
5
6
7
上次更新: 2024/08/14, 04:14:33
导航守卫
路由元信息

← 导航守卫 路由元信息→

最近更新
01
React Native 使用SVG
08-13
02
Docker基础命令
08-04
03
算数逻辑单元
07-30
更多文章>
Theme by Vdoing | Copyright © 2021-2024 WeiXiaojing | 友情链接
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式