您好,登錄后才能下訂單哦!
本文實(shí)例為大家分享了VUE多層路由嵌套的具體代碼,供大家參考,具體內(nèi)容如下
先看看效果圖:
例如:在做系統(tǒng)時(shí),主頁面有兩個(gè)功能【home】and【news】,在【home】下又分為登錄和注冊。
首先需要將各種模板進(jìn)行抽離。定義模板
<template id="home"> //home模板,里面含子視口 <div> <router-link to="/home/login">登錄</router-link> <router-link to="/home/zhuce">注冊</router-link> <router-view></router-view> </div> </template> <template id="news"> //消息模板 <div>news</div> </template> <template id="login"> //home模板下的登錄 <div>this is login</div> </template> <template id="zhuce"> //home模板下的注冊 <div>this is zhuce</div> </template>
JS下配置路由
const home={template:"#home"}; const news={template:'#news'}; const login={template:'#login'}; const zhuce={template:'#zhuce'}; var rout=[ {path:'/',redirect:'/home'}, //重定向?yàn)閔ome ,當(dāng)html后面哈希值為空時(shí),默認(rèn)顯示home { path:'/home', component:home, //模板注冊 redirect:'/home/login',//子視口的重定向 默認(rèn)登錄 children:[ {path:'/home/login',component:login}, //配置子模板 {path:'/home/zhuce',component:zhuce} ]}, {path:'/news',component:news} ]; var router=new VueRouter({ //實(shí)例化一個(gè)vuerouter routes:rout }); const app = new Vue({ router }).$mount('#app')
當(dāng)Vue實(shí)例沒有el屬性時(shí),則該實(shí)例尚沒有掛載到某個(gè)dom中;
假如需要延遲掛載,可以在之后手動(dòng)調(diào)用vm.$mount()方法來掛載。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。