问题简介:
- 登陆后,后台返回有路由列表。本地写好的有路由列表。通过两者对比,将相同的路由动态加载到路由中
- 通过for map 等进行对比。进入死循环
// 返回的路由列表 截取一个
{
id: 2,
path: '/Article',
name: '/Article',
meta: {
title: '文章管理',
icon: '_Article_management'
},
component: Main,
children: [
{
id: 21,
pid: 2,
path: 'articletype',
name: 'articletype',
meta: {
title: '文章类型列表',
},
component: () => import('@/view/Article/articletype/index.vue')
},
{
id: 22,
pid: 2,
path: 'article',
name: 'article',
meta: {
title: '文章列表',
},
component: () => import('@/view/Article/article/index.vue')
},
]
}
// 本地路由表
{
id: 2,
path: '/Article',
name: '/Article',
meta: {
title: '文章管理',
icon: '_Article_management'
},
component: Main,
children: [
{
id: 21,
pid: 2,
path: 'articletype',
name: 'articletype',
meta: {
title: '文章类型列表',
},
component: () => import('@/view/Article/articletype/index.vue')
},
{
id: 22,
pid: 2,
path: 'article',
name: 'article',
meta: {
title: '文章列表',
},
component: () => import('@/view/Article/article/index.vue')
},
]
}
{
id: 3,
path: '/Ordering',
name: '/Ordering',
meta: {
title: '订货会管理',
icon: '_Ordering'
},
component: Main,
children: [
{
id: 31,
pid: 3,
path: 'web-meeting',
name: 'web-meeting',
meta: {
title: '主题列表'
},
component: () => import('@/view/Ordering/web-meeting/index.vue')
},
{
id: 32,
pid: 3,
path: 'web-meetingStatus',
name: 'web-meetingStatus',
meta: {
title: '商品上线'
},
component: () => import('@/view/Ordering/web-meetingStatus/index.vue')
},
{
id: 33,
pid: 3,
path: 'web-meetingCart',
name: 'web-meetingCart',
meta: {
title: '购物车管理'
},
component: () => import('@/view/Ordering/web-meetingCart/index.vue')
}
]
},
- 两者是相同的。 通过id 进行判断(这样是错误的。因为id 会变动。但是没什么问题。改成其他的也可以)
如何对比两者,避免死循环
死循环产生(当本地多写一组路由数据,就会产生) 现代码本地比返回的数据多一组。产生死循环 求解决