一、前言

好几天没更文了,周末真的太冷了,在家躺了一天不爱动。今天给暖气了,相对不那么冷了,就可以继续更文了。

由文章标题不难看出,就是实现点击菜单跳转的意思,我写的很直白了,哈哈。

二、实现点击菜单跳转

1、统一页面命名方式

我们先将页面命名统一,都用小写形式,将HomeAbout页面都改为小写,接着再将routerindex.ts修改。

示例代码如下:

import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Home from '../views/home.vue'
import About from '../views/about.vue' const routes: Array<RouteRecordRaw> = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
component: About
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
//懒加载让我删掉了
}
] const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
}) export default router

2、新增管理页面

views/admin下创建页面为admin-ebook.vue,示例代码如下:

<template>
<div class="about">
<h1>电子书管理页面</h1>
</div>
</template>

3、添加路由

再次修改routerindex.ts内容,示例代码如下:

import {createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'
import Home from '../views/home.vue'
import About from '../views/about.vue'
import AdminEbook from '../views/admin/admin-ebook.vue' const routes: Array<RouteRecordRaw> = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
component: About
},
{
path: '/admin/admin-ebook',
name: 'AdminEbook',
component: AdminEbook
}
] const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
}) export default router

4、在菜单中绑定路由

我们在header中修改,示例代码如下:

<template>
<a-layout-header class="header">
<div class="logo" />
<a-menu
theme="dark"
mode="horizontal"
:style="{ lineHeight: '64px' }"
>
<a-menu-item key="/">
<router-link to="/">首页</router-link>
</a-menu-item>
<a-menu-item key="/admin/admin-ebook">
<router-link to="/admin/admin-ebook">电子书管理页面</router-link>
</a-menu-item>
<a-menu-item key="3">
<router-link to="/about">关于我们</router-link>
</a-menu-item>
</a-menu>
</a-layout-header>
</template> <script lang="ts">
import {defineComponent} from 'vue'; export default defineComponent({
name: 'TheHeader',
});
</script>

知识点:

使用router-link跳转,示例如下:<router-link to="/">首页</router-link>

三、实际效果

重新编译启动,如下图:

到此,页面、菜单、路由的分享完毕。

最新文章

  1. Python’s SQLAlchemy vs Other ORMs[转发 3]Django&#39;s ORM
  2. Python :open文件操作,配合read()使用!
  3. 屏幕适配1(Android 增强版百分比布局库 为了适配而扩展)
  4. 国内第一篇详细讲解hadoop2的automatic HA+Federation+Yarn配置的教程
  5. 将普通工程转为mvn标准工程(main resources)
  6. springmvc单文件上传
  7. leetcode:String to Integer (atoi)
  8. Windows下用cmd命令安装及卸载服务
  9. &lt;转&gt;详解DNS的常用记录(下):DNS系列之三
  10. EF Code First学习笔记 初识Code First
  11. [React Testing] Setting up dependencies &amp;&amp; Running tests
  12. ZOJ Monthly, June 2014 月赛BCDEFGH题题解
  13. MVC 传参
  14. Java引用类型变量
  15. Ubuntu 16.04系统下出现E: 无法下载 http://ppa.launchpad.net/fcitx-team/nightly/ubuntu/dists/xenial/main/binary-amd64/Packages 404 Not Found
  16. Chapter 1:Introduction
  17. C# 在RichTextBox中滚动鼠标时滚动的是父窗口的滚动条
  18. CS:APP3e 深入理解计算机系统_3e C Programming Lab实验
  19. Linux几个小杂碎点(更新中)
  20. Linux下批量添加用户

热门文章

  1. math.h库详解
  2. 学习PHP中好玩的Gmagick图像操作扩展的使用
  3. symfony2 数据库原生查询
  4. AD学习笔记(基础)
  5. 动图图解GC算法 - 让垃圾回收动起来!
  6. CF700E-Cool Slogans【SAM,线段树合并,dp】
  7. MyBatis切换至MyBatis-plus踩坑Invalid bound statement (not found):
  8. 腾讯首个CNCF沙箱开源项目
  9. 12c slience dbca ORA-27125
  10. 【vscode高级玩家】Visual Studio Code❤️安装教程(最新版&#127881;教程小白也能看懂!)