Vue3 頁面,菜單,路由的使用
一、實現(xiàn)點(diǎn)擊菜單跳轉(zhuǎn)
1、統(tǒng)一頁面命名方式
我們先將頁面命名統(tǒng)一,都用小寫形式,將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
2、新增管理頁面
在views/admin下創(chuàng)建頁面為admin-ebook.vue,
示例代碼如下:
<template>
<div class="about">
<h1>電子書管理頁面</h1>
</div>
</template>
3、添加路由
再次修改router中index.ts內(nèi)容,
示例代碼如下:
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">關(guān)于我們</router-link>
</a-menu-item>
</a-menu>
</a-layout-header>
</template>
<script lang="ts">
import {defineComponent} from 'vue';
export default defineComponent({
name: 'TheHeader',
});
</script>
知識點(diǎn):
使用router-link跳轉(zhuǎn),示例如下: <router-link to="/">首頁</router-link>
二、實際效果
重新編譯啟動,如下圖:

到此這篇關(guān)于Vue3之 頁面,菜單,路由的使用的文章就介紹到這了,更多相關(guān)Vue3之 頁面,菜單,路由的使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue router自動判斷左右翻頁轉(zhuǎn)場動畫效果
最近公司項目比較少終于有空來記錄一下自己對vue-router的一些小小的使用心得,本文給大家分享vue router自動判斷左右翻頁轉(zhuǎn)場動畫效果,感興趣的朋友一起看看吧2017-10-10
詳解vue-cli腳手架build目錄中的dev-server.js配置文件
這篇文章主要介紹了詳解vue-cli腳手架build目錄中的dev-server.js配置文件,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11
vue使用axios導(dǎo)出后臺返回的文件流為excel表格詳解
這篇文章主要介紹了vue使用axios導(dǎo)出后臺返回的文件流為excel表格方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08
Element-ui設(shè)置el-table表頭全選框隱藏或禁用
這篇文章主要給大家介紹了關(guān)于Element-ui設(shè)置el-table表頭全選框隱藏或禁用的相關(guān)資料,文中手把手教你實現(xiàn)el-table實現(xiàn)跨表格禁用選項,需要的朋友可以參考下2023-07-07

