動態(tài)菜單欄渲染奴曙,和路由的配置

渲染多級菜單欄

1 根據路由固定渲染

template部分
v-for="(nav, index) in navs"  //一級菜單欄循環(huán)

// !!特別注意挥吵,二級循環(huán)是從上一級的nav開始循環(huán)裤唠,不是沖原來的數據開始
v-for="item in nav.children.filter(item => item.meta.isChild === true)"  // 二級菜單循環(huán)

// js 部分
data () {
    return {
      navs: routes.filter(route => route.meta.isNavsItem === true) //固定的渲染
    }
  }

2 后臺數據動態(tài)渲染菜單欄

template的循環(huán)部分和固定渲染一樣
// 特別注意的是!二級菜單中泥张,后臺跳path要和前端routes保持一致才能跳轉到相應的網頁呵恢。
<el-menu-item v-for="item in nav.children"
                               @click="handleRoute(item.path)"
                               :key="item.title"
                               active-text-color="#dedede"
>
   {{item.title}}
</el-menu-item>
js部分
data () {
    return {
      netNavs: []
    }
  }
created () {
    // console.log(this.navs)菜單欄的動態(tài)渲染
    this.$http.getSideBar().then(res => {
      let barData = res.data
      this.netNavs.push(...barData) // 后端獲取數據賦值到data里面
    })
  }
  1. routes寫法

    export default [
      {
        path: '/',
        redirect: '/index',
        components: {
          default: Index,
          leftnavs: icSidebar
        },
        meta: {
          isNavsItem: false,
          hasChild: false
        }
      }, {
        path: '/index',
        name: 'index',
        components: {
          default: Index,
          leftnavs: icSidebar
        },
        meta: {
          isNavsItem: false,
          hasChild: false
        }
      }, {
        path: '/admin/netbar',
        name: 'netbar',
        components: {
          default: Index,
          leftnavs: icSidebar
        },
        meta: {
          isNavsItem: true,
          title: '網吧管理',
          hasChild: true
        },
        children: [ // 二級菜單
          {
            path: '/admin/netbar/intercafe',
            component: InterCafe,
            name: 'intercafe',
            meta: {
              title: '網吧管理',
              isChild: true
            }
          }, {
            path: '/admin/netbar/room',
            component: Rooms,
            name: 'Rooms',
            meta: {
              title: '包房管理',
              isChild: true
            }
          }, {
            path: '/admin/netbar/roomset',
            component: RoomsSet,
            name: 'roomsset',
            meta: {
              title: '包間設置',
              isChild: true
            }
          }, {
            path: '/admin/netbar/roomorders',
            component: RoomsOrders,
            name: 'roomorders',
            meta: {
              title: '包間訂單',
              isChild: true
            }
          }
        ]
      }, {
        path: '/admin/outfood',
        name: 'outFood',
        components: {
          default: Index,
          leftnavs: icSidebar
        },
        meta: {
          isNavsItem: true,
          title: '外賣管理',
          hasChild: true
        },
        children: [
          {
            path: '/admin/outfood/classify',
            component: Classify,
            name: 'classify',
            meta: {
              title: '分類管理',
              isChild: true
            }
          }, {
            path: '/admin/outfood/products',
            component: Products,
            name: 'products',
            meta: {
              title: '商品管理',
              isChild: true
            }
          }, {
            path: '/admin/outfood/orders',
            component: Orders,
            name: 'orders',
            meta: {
              title: '訂單管理',
              isChild: true
            }
          }, {
            path: '/admin/outfood/set',
            component: Set,
            name: 'set',
            meta: {
              title: '設置管理',
              isChild: true
            }
          }
        ]
      }, {
        path: '/admin/user',
        name: 'users',
        components: {
          default: Index,
          leftnavs: icSidebar
        },
        meta: {
          isNavsItem: true,
          title: '用戶管理',
          hasChild: true
        },
        children: [
          {
            path: '/admin/user/userlist',
            component: Users,
            name: 'userlist',
            meta: {
              title: '用戶列表',
              isChild: true
            }
          }, {
            path: '/admin/user/pointlist',
            component: PointsList,
            name: 'points',
            meta: {
              title: '積分列表',
              isChild: true
            }
          }, {
            path: '/admin/user/grade',
            component: GradeSet,
            name: 'grade',
            meta: {
              title: '等級設置',
              isChild: true
            }
          }, {
            path: '/admin/user/viphandle',
            component: VipHandle,
            name: 'viphandle',
            meta: {
              title: 'VIP管理',
              isChild: true
            }
          }, {
            path: '/admin/user/viphandle/failvip', // 過期vip
            component: FailVip,
            name: 'failVip',
            meta: {
              title: '過期VIP',
              isChild: false
            }
          }
        ]
      }, {
        path: '/admin/account',
        name: 'account',
        components: {
          default: Index,
          leftnavs: icSidebar
        },
        meta: {
          isNavsItem: true,
          title: '賬號管理',
          hasChild: true
        },
        children: [
          {
            path: '/admin/account/accountlist',
            component: Account,
            name: 'accountlist',
            meta: {
              title: '賬號管理',
              isChild: true
            }
          }
        ]
      }, {
        path: '/admin/financial',
        name: 'financial',
        components: {
          default: Index,
          leftnavs: icSidebar
        },
        meta: {
          isNavsItem: true,
          title: '財務管理',
          hasChild: true
        },
        children: [
          {
            path: '/admin/financial/charge',
            component: ChargeRecord,
            name: 'charge',
            meta: {
              title: '充值統(tǒng)計',
              isChild: true
            }
          }, {
            path: '/admin/financial/pay',
            component: PayRecored,
            name: 'pay',
            meta: {
              title: '消費統(tǒng)計',
              isChild: true
            }
          }
        ]
      }, {
        path: '/admin/notice',
        name: 'notice',
        components: {
          default: Index,
          leftnavs: icSidebar
        },
        meta: {
          isNavsItem: true,
          title: '公告管理',
          hasChild: true
        },
        children: [
          {
            path: '/admin/noticelist',
            component: Notice,
            name: 'noticelist',
            meta: {
              title: '公告管理',
              isChild: true
            }
          }, {
            path: '/admin/noticelist/add', // 添加公告
            component: NoticeAdd,
            name: 'noticeadd',
            meta: {
              title: '添加公告',
              isChild: false
            }
          }, {
            path: '/admin/noticelist/edit/:editId', // 修改公告
            component: NoticeEdit,
            name: 'noticeedit',
            meta: {
              title: '修改公告',
              isChild: false
            }
          }
        ]
      }
    ]
    
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市媚创,隨后出現(xiàn)的幾起案子渗钉,更是在濱河造成了極大的恐慌,老刑警劉巖钞钙,帶你破解...
    沈念sama閱讀 217,826評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件鳄橘,死亡現(xiàn)場離奇詭異,居然都是意外死亡芒炼,警方通過查閱死者的電腦和手機瘫怜,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,968評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來本刽,“玉大人鲸湃,你說我怎么就攤上這事∽釉ⅲ” “怎么了暗挑?”我有些...
    開封第一講書人閱讀 164,234評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長别瞭。 經常有香客問我窿祥,道長,這世上最難降的妖魔是什么蝙寨? 我笑而不...
    開封第一講書人閱讀 58,562評論 1 293
  • 正文 為了忘掉前任晒衩,我火速辦了婚禮,結果婚禮上墙歪,老公的妹妹穿的比我還像新娘听系。我一直安慰自己,他們只是感情好虹菲,可當我...
    茶點故事閱讀 67,611評論 6 392
  • 文/花漫 我一把揭開白布靠胜。 她就那樣靜靜地躺著,像睡著了一般毕源。 火紅的嫁衣襯著肌膚如雪浪漠。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,482評論 1 302
  • 那天霎褐,我揣著相機與錄音址愿,去河邊找鬼。 笑死冻璃,一個胖子當著我的面吹牛响谓,可吹牛的內容都是我干的损合。 我是一名探鬼主播,決...
    沈念sama閱讀 40,271評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼娘纷,長吁一口氣:“原來是場噩夢啊……” “哼嫁审!你這毒婦竟也來了?” 一聲冷哼從身側響起赖晶,我...
    開封第一講書人閱讀 39,166評論 0 276
  • 序言:老撾萬榮一對情侶失蹤律适,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后嬉探,有當地人在樹林里發(fā)現(xiàn)了一具尸體擦耀,經...
    沈念sama閱讀 45,608評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡棉圈,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,814評論 3 336
  • 正文 我和宋清朗相戀三年涩堤,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片分瘾。...
    茶點故事閱讀 39,926評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡胎围,死狀恐怖,靈堂內的尸體忽然破棺而出德召,到底是詐尸還是另有隱情白魂,我是刑警寧澤,帶...
    沈念sama閱讀 35,644評論 5 346
  • 正文 年R本政府宣布上岗,位于F島的核電站福荸,受9級特大地震影響,放射性物質發(fā)生泄漏肴掷。R本人自食惡果不足惜敬锐,卻給世界環(huán)境...
    茶點故事閱讀 41,249評論 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望呆瞻。 院中可真熱鬧台夺,春花似錦、人聲如沸痴脾。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,866評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽赞赖。三九已至滚朵,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間前域,已是汗流浹背辕近。 一陣腳步聲響...
    開封第一講書人閱讀 32,991評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留话侄,地道東北人亏推。 一個月前我還...
    沈念sama閱讀 48,063評論 3 370
  • 正文 我出身青樓学赛,卻偏偏與公主長得像,于是被迫代替她去往敵國和親吞杭。 傳聞我的和親對象是個殘疾皇子盏浇,可洞房花燭夜當晚...
    茶點故事閱讀 44,871評論 2 354

推薦閱讀更多精彩內容