重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
本文實例為大家分享了VUE多層路由嵌套的具體代碼,供大家參考,具體內容如下
成都創新互聯是一家專業提供尼金平企業網站建設,專注與成都網站設計、成都網站制作、H5建站、小程序制作等業務。10年已為尼金平眾多企業、政府機構等服務。創新互聯專業網站設計公司優惠進行中。
先看看效果圖:
例如:在做系統時,主頁面有兩個功能【home】and【news】,在【home】下又分為登錄和注冊。
首先需要將各種模板進行抽離。定義模板
//home模板,里面含子視口//消息模板登錄 注冊 news//home模板下的登錄this is login//home模板下的注冊this is zhuce
JS下配置路由
const home={template:"#home"}; const news={template:'#news'}; const login={template:'#login'}; const zhuce={template:'#zhuce'}; var rout=[ {path:'/',redirect:'/home'}, //重定向為home ,當html后面哈希值為空時,默認顯示home { path:'/home', component:home, //模板注冊 redirect:'/home/login',//子視口的重定向 默認登錄 children:[ {path:'/home/login',component:login}, //配置子模板 {path:'/home/zhuce',component:zhuce} ]}, {path:'/news',component:news} ]; var router=new VueRouter({ //實例化一個vuerouter routes:rout }); const app = new Vue({ router }).$mount('#app')
當Vue實例沒有el屬性時,則該實例尚沒有掛載到某個dom中;
假如需要延遲掛載,可以在之后手動調用vm.$mount()方法來掛載。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持創新互聯。