问答

vue-router动态路由动态添加子路由

作者:admin 2021-05-05 我要评论

routes: [ { path: '/toOne/:id', name: 'toOneName', component: one, children: [ {path: '/profile', component: oneNext}, {path: '/posts', component: two...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)
routes: [
    { path: '/toOne/:id', name: 'toOneName', component: one,
         children: [
         {path: '/profile', component: oneNext},
         {path: '/posts', component: twoNext}
        ]
    }  
]

我要在children通过动态路由的方式添加一个子路由,如何操作
{path: '/gets', component: threeNext}
this.$router.addRoutes()

###

这么写就好了

export const initRouterNode = (routers, data) => {
 for (var item of data) {
 let menu = Object.assign({}, item)
 // menu.component = import(`@/views/${menu.component}.vue`);
 menu.component = lazyLoading(menu.component)
 if (item.children && item.children.length > 0) {
 menu.children = []
 initRouterNode(menu.children, item.children)
 } routers.push(menu)
 }}

routers 是生成后的路由, data 是后端返回的路由数据 tree , lazyLoading 是懒加载路由

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • vue-router动态路由动态添加子路由

    vue-router动态路由动态添加子路由

  • bizcharts 分面图

    bizcharts 分面图

  • C++编译时出现字符串转换错误,求解决

    C++编译时出现字符串转换错误,求解决

  • 请教一下大佬,图一报错的原因是什么?

    请教一下大佬,图一报错的原因是什么?

腾讯云代理商
海外云服务器