- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) > web開(kāi)發(fā) > JavaScript >
- vue router-view的嵌套顯示實(shí)現
const routes = [ { path: '/', name: '導航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: '導航2', component: Home, children:[ { path: '/pageThree', name: '頁(yè)面3', component: PageThree, }, { path: '/pageFour', name: '頁(yè)面4', component: PageFour }, ] },
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>
首先,在訪(fǎng)問(wèn)http://localhost:8181/時(shí)會(huì )進(jìn)入第一層嵌套,此時(shí)進(jìn)入第一個(gè)router-view:Home.vue。然后當訪(fǎng)問(wèn)pageone時(shí),會(huì )連帶Home.vue繼續訪(fǎng)問(wèn)。
因為router-view的嵌套顯示和路由路基的嵌套有關(guān),可以看到,在路由里面,導航一的路徑底下分別是頁(yè)面一以及頁(yè)面二的路由路徑。所以當訪(fǎng)問(wèn)頁(yè)面一pageone時(shí),會(huì )先訪(fǎng)問(wèn)上級路徑Home.vue頁(yè)面。加入Home.vue頁(yè)面沒(méi)有放置router-view,那么下級頁(yè)面將無(wú)法顯示
到此這篇關(guān)于vue router-view的嵌套顯示實(shí)現的文章就介紹到這了,更多相關(guān)vue router-view嵌套顯示內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站