Vue3中实现点击菜单跳转效果怎么做,要点是什么
Admin 2022-06-20 群英技术资讯 1389 次浏览
我们先将页面命名统一,都用小写形式,将Home
、About
页面都改为小写,接着再将router
中index.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
在views/admin
下创建页面为admin-ebook.vue
,
示例代码如下:
<template> <div class="about"> <h1>电子书管理页面</h1> </div> </template>
再次修改router
中index.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
我们在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>
重新编译启动,如下图:
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
目录一、正则元字符1、 字符元字符2、重复元字符(量词)3、定位元字符4、分组和替换字符5、特殊字符6、需要转义的字符7、贪婪与非贪婪匹配8、常见正则表达式二、正则表达式应用举例1、验证表达式vs中批量操作三、文件夹中的文件内容正则批量替换1、使用VSCode文件替换(使用JS引擎)2、文件夹中的文件内容正则批量替换一
目录概念介绍第一种:递归方式(推荐,项目中最安全最常用)第二种:JSON.stringify() ;(这个不推荐使用,有坑)第三种:使用第三方库lodash中的cloneDeep()方法第四种:JQuery的extend()方法进行深拷贝(推荐在JQ中使用)总结概念介绍深拷贝:在堆内存中重新开辟一个存储空间,完全克隆一
JavaScript中的变量是松散类型的,可以保存任何类型数据,变量只不过是一个名称,下面这篇文章主要给大家介绍了关于JavaScript变量声明的var、let、const的相关资料,需要的朋友可以参考下
这篇文章主要为大家介绍了javascript进阶篇深拷贝实现的四种方式详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
基于element-plus的二次封装数据双向绑定在实际开发中,经常需要基于element-plus封装一些自己的定制化组件,方便快速构建我们当前的业务。在vue2.0中父子组件数据的双向绑定通
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008