Pinia+Router学习笔记(十四)

简介: 本节记录Vue-Router中路由过渡动效相关内容

在进行路由跳转的时候我们也可以设置一些动效,让整个过程看起来没那么枯燥(这里使用animate.css动画库)

import { createApp, toRaw } from 'vue'
import router from './router'
import App from './App.vue'
// 引入动画库
import 'animate.css'
const app = createApp(App)

app.use(router)

app.mount('#app')
<template>
  <div>
    <router-view #default="{ route, Component }">
      <transition
        :enter-active-class="`animate__animated animate__backInRight`"
        >
        <component :is="Component"></component>
      </transition>
    </router-view>
  </div>
</template>

<script setup lang="ts">
  import { ref, reactive } from 'vue'
</script>

<style scoped></style>

router-view有一个默认作用域插槽,接收两个变量route和Component,route包含跳转时的一些路由信息,Component则是VNode,可通过动态组件展示在页面上。上图这样的处理方式让所有的路由都使用animate__backInRight这个动画,如果想让不同路由组件使用不同动画可以在meta中定义动画名

<template>
  <div>
    <router-view #default="{ route, Component }">
<!--       定义动画类名,从route.meta中取 -->
      <transition
        :enter-active-class="`animate__animated ${route.meta.transition}`"
        >
        <component :is="Component"></component>
      </transition>
    </router-view>
  </div>
</template>

<script setup lang="ts">
  import { ref, reactive } from 'vue'
</script>

<style scoped></style>
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

// declare声明模块防止类型报错
declare module 'vue-router' {
  interface RouteMeta {
    transition: string
  }
}

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    meta: {
      // 定义动画名
      transition: 'animate__backInRight',
    },
    component: () => import('../components/login.vue'),
  },
  {
    path: '/reg',
    component: () => import('../components/reg.vue'),
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

router.beforeEach((to, from, next) => {
  next(true)
})

export default router
相关文章
|
2天前
|
数据采集 人工智能 安全
|
11天前
|
云安全 监控 安全
|
3天前
|
自然语言处理 API
万相 Wan2.6 全新升级发布!人人都能当导演的时代来了
通义万相2.6全新升级,支持文生图、图生视频、文生视频,打造电影级创作体验。智能分镜、角色扮演、音画同步,让创意一键成片,大众也能轻松制作高质量短视频。
1021 151
|
3天前
|
编解码 人工智能 机器人
通义万相2.6,模型使用指南
智能分镜 | 多镜头叙事 | 支持15秒视频生成 | 高品质声音生成 | 多人稳定对话
|
17天前
|
机器学习/深度学习 人工智能 自然语言处理
Z-Image:冲击体验上限的下一代图像生成模型
通义实验室推出全新文生图模型Z-Image,以6B参数实现“快、稳、轻、准”突破。Turbo版本仅需8步亚秒级生成,支持16GB显存设备,中英双语理解与文字渲染尤为出色,真实感和美学表现媲美国际顶尖模型,被誉为“最值得关注的开源生图模型之一”。
1720 9
|
8天前
|
人工智能 自然语言处理 API
一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸
一句话生成拓扑图!next-ai-draw-io 结合 AI 与 Draw.io,通过自然语言秒出架构图,支持私有部署、免费大模型接口,彻底解放生产力,绘图效率直接爆炸。
660 152
|
10天前
|
人工智能 安全 前端开发
AgentScope Java v1.0 发布,让 Java 开发者轻松构建企业级 Agentic 应用
AgentScope 重磅发布 Java 版本,拥抱企业开发主流技术栈。
625 13
|
5天前
|
SQL 自然语言处理 调度
Agent Skills 的一次工程实践
**本文采用 Agent Skills 实现整体智能体**,开发框架采用 AgentScope,模型使用 **qwen3-max**。Agent Skills 是 Anthropic 新推出的一种有别于mcp server的一种开发方式,用于为 AI **引入可共享的专业技能**。经验封装到**可发现、可复用的能力单元**中,每个技能以文件夹形式存在,包含特定任务的指导性说明(SKILL.md 文件)、脚本代码和资源等 。大模型可以根据需要动态加载这些技能,从而扩展自身的功能。目前不少国内外的一些框架也开始支持此种的开发方式,详细介绍如下。
385 4