VUE多层路由嵌套实现代码

网友投稿 234 2023-05-15


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后面哈希值jTkuhRQfmR为空时,默认显示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()方法来挂载。


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java中泛型使用实例详解
下一篇:java加载properties文件的六种方法总结
相关文章

 发表评论

暂时没有评论,来抢沙发吧~