vue router-view的巢狀顯示實現
阿新 • • 發佈:2021-08-02
目錄
- 一、路由配置
- 二、頁面巢狀
- 三、巢狀聯絡
一、路由配置
const routes = [ { path: '/',name: '導航1',component: Home,children:[ { path: '/customer',name: 'Customer',// route level code-splitting // this generates a separate chunk (about.[hash].) for this route // which is lazy-loaded when the route is visited. component: () => import(/* webpackChunkName: "about" */ '../views/Customer.vue') },http://www.cppcns.com{ path: '/pageOne',name: '頁面1',component: PageOne,},{ path: '/pageTwo',name: '頁面2',cohttp://www.cppcns.commponent: PageTwo,] },{ path: '/navigation',name: '導航2',children:[ { path: '/pageThree',name: '頁面3',component: PageThree,{ path: '/pageFour',name: '頁面4',component: PageFour },
二、vue頁面巢狀
App.vue先配置第一個router-view
// An highlighted block <router-view></router-view>
Home.vue配置第二個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+''"> <templateslot="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&www.cppcns.comgt; </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>
三、巢狀聯絡
首先,在訪問http://localhost:8181/時會進入第一層www.cppcns.com巢狀,此時進入第一個router-view:Home.vue。然後當訪問pageone時,會連帶Home.vue繼續訪問。
因為router-view的巢狀顯示和路由路基的巢狀有關,可以看到,在路由裡面,導航一的路徑底下分別是頁面一以及頁面二的路由路徑。所以當訪問頁面一pageone時,會先訪問上級路徑Home.vue頁面。加入Home.vue頁面沒有放置router-view,那麼下級頁面將無法顯示
到此這篇關於vue router-view的巢狀顯示實現的文章就介紹到這了,更多相關vue router-view巢狀顯示內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!