vue router-view的嵌套顯示實(shí)現(xiàn)
一、路由配置
const routes = [
{
path: '/',
name: '導(dǎo)航1',
component: Home,
children:[
{
path: '/customer',
name: 'Customer',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/Customer.vue')
},
{
path: '/pageOne',
name: '頁(yè)面1',
component: PageOne,
},
{
path: '/pageTwo',
name: '頁(yè)面2',
component: PageTwo,
},
]
},
{
path: '/navigation',
name: '導(dǎo)航2',
component: Home,
children:[
{
path: '/pageThree',
name: '頁(yè)面3',
component: PageThree,
},
{
path: '/pageFour',
name: '頁(yè)面4',
component: PageFour
},
]
},
二、vue頁(yè)面嵌套
App.vue先配置第一個(gè)router-view
// An highlighted block <router-view></router-view>
Home.vue配置第二個(gè)router-view
// An highlighted block
<template>
<div>
<el-container style="height: 500px; border: 1px solid #eee">
<el-aside width="200px" style="background-color: rgb(238, 241, 246)">
<el-menu>
<el-submenu v-for="(item,index) in $router.options.routes" :index="index+''">
<template slot="title"><i class="el-icon-sell"></i>{{item.name}}</template>
<el-menu-item v-for="(item2,index2) in item.children" :index="index+'-'+index2">{{item2.name}}</el-menu-item>
</el-submenu>
</el-menu>
</el-aside>
<el-container>
<el-header style="text-align: right; font-size: 12px">
<el-dropdown>
<i class="el-icon-setting" style="margin-right: 15px"></i>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item>查看</el-dropdown-item>
<el-dropdown-item>新增</el-dropdown-item>
<el-dropdown-item>刪除</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<span>王小虎</span>
</el-header>
<el-main>
<router-view></router-view>
</el-main>
</el-container>
</el-container>
</div>
</template>
<style>
.el-header {
background-color: #B3C0D1;
color: #333;
line-height: 60px;
}
.el-aside {
color: #333;
}
</style>
<script>
export default {
};
</script>
三、嵌套聯(lián)系
首先,在訪問(wèn)http://localhost:8181/時(shí)會(huì)進(jìn)入第一層嵌套,此時(shí)進(jìn)入第一個(gè)router-view:Home.vue。然后當(dāng)訪問(wèn)pageone時(shí),會(huì)連帶Home.vue繼續(xù)訪問(wèn)。
因?yàn)閞outer-view的嵌套顯示和路由路基的嵌套有關(guān),可以看到,在路由里面,導(dǎo)航一的路徑底下分別是頁(yè)面一以及頁(yè)面二的路由路徑。所以當(dāng)訪問(wèn)頁(yè)面一pageone時(shí),會(huì)先訪問(wèn)上級(jí)路徑Home.vue頁(yè)面。加入Home.vue頁(yè)面沒(méi)有放置router-view,那么下級(jí)頁(yè)面將無(wú)法顯示
到此這篇關(guān)于vue router-view的嵌套顯示實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)vue router-view嵌套顯示內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue實(shí)現(xiàn)把頁(yè)面導(dǎo)出成word文件的方法
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)把頁(yè)面導(dǎo)出成word文件的方法,文中的實(shí)現(xiàn)步驟講解詳細(xì),并且有詳細(xì)的代碼示例,需要的小伙伴可以參考一下2023-10-10
Vue實(shí)現(xiàn)Excel本地下載及上傳的方法詳解
相信大家在項(xiàng)目中經(jīng)常會(huì)遇到一些上傳下載文件的相關(guān)功能。這篇文章將為大家介紹一下Vue實(shí)現(xiàn)Excel本地下載及上傳的示例代碼,需要的可以參考一下2022-07-07
JSON數(shù)組和JSON對(duì)象在vue中的獲取方法
這兩天在學(xué)習(xí)vue,主要是為了實(shí)現(xiàn)前后端的分離,因此數(shù)據(jù)的傳輸是必不可少的一個(gè)環(huán)節(jié),這篇文章主要介紹了JSON數(shù)組和JSON對(duì)象在vue中的獲取方法,需要的朋友可以參考下2022-09-09
詳解vite2.0配置學(xué)習(xí)(typescript版本)
這篇文章主要介紹了詳解vite2.0配置學(xué)習(xí)(typescript版本),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02
vue?動(dòng)態(tài)添加el-input的實(shí)現(xiàn)邏輯
這篇文章主要介紹了vue?動(dòng)態(tài)添加el-input的實(shí)現(xiàn)代碼,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06
vue2.0項(xiàng)目實(shí)現(xiàn)路由跳轉(zhuǎn)的方法詳解
這篇文章主要介紹了vue2.0項(xiàng)目實(shí)現(xiàn)路由跳轉(zhuǎn)的詳細(xì)方法,非常不錯(cuò),具有一定的參考借鑒借鑒價(jià)值,需要的朋友可以參考下2018-06-06

