189 8069 5689

VUE多层路由嵌套实现代码

本文实例为大家分享了VUE多层路由嵌套的具体代码,供大家参考,具体内容如下

成都创新互联是一家专业提供尼金平企业网站建设,专注与成都网站设计、成都网站制作、H5建站、小程序制作等业务。10年已为尼金平众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。

先看看效果图:

VUE多层路由嵌套实现代码

例如:在做系统时,主页面有两个功能【home】and【news】,在【home】下又分为登录和注册。

首先需要将各种模板进行抽离。定义模板






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()方法来挂载。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。


文章题目:VUE多层路由嵌套实现代码
本文地址:http://cdxtjz.cn/article/jijeed.html

其他资讯