vue.js使用Element-ui實(shí)現(xiàn)導(dǎo)航菜單
本文實(shí)例為大家分享了vue.js使用Element-ui中實(shí)現(xiàn)導(dǎo)航菜單的具體代碼,供大家參考,具體內(nèi)容如下
寫這個(gè)的原因是因?yàn)楫?dāng)時(shí)寫這個(gè)功能時(shí)候element只有效果,但是功能沒有實(shí)現(xiàn),當(dāng)時(shí)一頭霧水
先放圖吧
大體實(shí)現(xiàn)思路我先講一下不然下面代碼片段會(huì)看懵,圈出來的左右兩部分,左邊是element復(fù)制就可實(shí)現(xiàn),右邊是跳轉(zhuǎn)的子組件。
首先創(chuàng)建導(dǎo)航菜單的vue文件,但這個(gè)文件里面只是引入組件,里面使用Container布局容器實(shí)現(xiàn)左右兩部分,左邊el-aside標(biāo)簽中放入導(dǎo)航菜單的組件,右邊el-main標(biāo)簽中寫<router-view></router-view>實(shí)現(xiàn)路由跳轉(zhuǎn)即可
導(dǎo)航菜單文件我起名為Elnav.vue
<template> <div class="app"> <el-container> <el-aside> <navmenu></navmenu> </el-aside> <el-main> <router-view></router-view> </el-main> </el-container> </div> </template> <script> import navmenu from './navmenu' export default { data() { return { } }, components:{ navmenu } } </script> <style scoped> </style>
里面主要引入navmenu組件(navmenu組件就是elemet中的樣式)
navmenu.vue中
注意設(shè)置 default-active="$route.path"以及組件跳轉(zhuǎn)(選項(xiàng)一/二)的index值
<template> <div> <el-row> <el-col> <el-menu default-active="$route.path" router class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" > <el-submenu index="1"> <template slot="title"> <i class="el-icon-location"></i> <span>導(dǎo)航一</span> </template> <el-menu-item-group> <template slot="title">分組一</template> <el-menu-item index="/Elnav/one">選項(xiàng)1</el-menu-item> <el-menu-item index="/Elnav/two">選項(xiàng)2</el-menu-item> </el-menu-item-group> <el-menu-item-group title="分組2"> <el-menu-item index="1-3">選項(xiàng)3</el-menu-item> </el-menu-item-group> <el-submenu index="1-4"> <template slot="title">選項(xiàng)4</template> <el-menu-item index="1-4-1">選項(xiàng)1</el-menu-item> </el-submenu> </el-submenu> </el-menu> </el-col> </el-row> </div> </template> <script> export default { methods: { handleOpen(key, keyPath) { console.log(key, keyPath); }, handleClose(key, keyPath) { console.log(key, keyPath); } }, mounted() { console.log(this.$route); } }; </script> <style> </style>
接下來就是路由的配置
{ path: "/Elnav", name: "Elnav", component: () => import("../components/Elnav.vue"), children:[ { path: "/Elnav/one", name: "one", component: () => import("../components/one.vue") }, { path: "/Elnav/two", name: "two", component: () => import("../components/two.vue") } ] }
至于右邊內(nèi)容的one.vue以及其他vue文件的內(nèi)容就自己寫即可
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue項(xiàng)目中應(yīng)用ueditor自定義上傳按鈕功能
這篇文章主要介紹了vue項(xiàng)目中應(yīng)用ueditor自定義上傳按鈕功能,文中以vue-cli生成的項(xiàng)目為例給大家介紹了vue項(xiàng)目中使用ueditor的方法,感興趣的朋友跟隨腳本之家小編一起學(xué)習(xí)吧2018-04-04Vue 路由間跳轉(zhuǎn)和新開窗口的方式(query、params)
這篇文章主要介紹了Vue 路由間跳轉(zhuǎn)和新開窗口的方式,本文主要通過query方式和params方式介紹,需要的朋友可以參考下2019-12-12vant-list組件觸發(fā)多次onload事件導(dǎo)致數(shù)據(jù)亂序的解決方案
這篇文章主要介紹了vant-list組件觸發(fā)多次onload事件導(dǎo)致數(shù)據(jù)亂序的解決方案2023-01-01Vue.js實(shí)現(xiàn)簡單動(dòng)態(tài)數(shù)據(jù)處理
本篇文章主要介紹了Vue.js實(shí)現(xiàn)簡單動(dòng)態(tài)數(shù)據(jù)處理,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02Vue ElementUI實(shí)現(xiàn):限制輸入框只能輸入正整數(shù)的問題
這篇文章主要介紹了Vue ElementUI實(shí)現(xiàn):限制輸入框只能輸入正整數(shù)的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07Vue中props組件和slot標(biāo)簽的區(qū)別
props?和?slot?在?Vue?中的作用略有不同,props?更多地用于父子組件之間的數(shù)據(jù)傳遞,而?slot?則更多地用于組件的復(fù)用和擴(kuò)展。感興趣的同學(xué)可以參考閱讀2023-04-04vue項(xiàng)目引入百度地圖BMapGL鼠標(biāo)繪制和BMap輔助工具
這篇文章主要為大家介紹了vue項(xiàng)目引入百度地圖BMapGL鼠標(biāo)繪制和BMap輔助工具的踩坑分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02