VUE多层路由嵌套实现代码
更新时间:2017年05月15日 16:02:08 作者:WakMeUp
这篇文章主要为大家详细介绍了VUE多层路由嵌套的实现代码,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了VUE多层路由嵌套的具体代码,供大家参考,具体内容如下
先看看效果图:
例如:在做系统时,主页面有两个功能【home】and【news】,在【home】下又分为登录和注册。
首先需要将各种模板进行抽离。定义模板
<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'}, //重定向为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()方法来挂载。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
element日历calendar组件上月、今天、下月、日历块点击事件及模板源码
这篇文章主要介绍了element日历calendar组件上月、今天、下月、日历块点击事件及模板源码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-07-07关于vue中ref的使用(this.$refs获取为undefined)
这篇文章主要介绍了关于vue中ref的使用(this.$refs获取为undefined),具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2022-03-03Vue element el-table-column中对日期进行格式化方式(全局过滤器)
这篇文章主要介绍了Vue element el-table-column中对日期进行格式化方式(全局过滤器),具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2023-04-04
最新评论