vue3 element-plus二次封裝組件系列之伸縮菜單制作
1、效果
折疊效果--只剩圖標(biāo)
展開(kāi)效果--有圖標(biāo)有文字
2、主要邏輯代碼
home.vue--主頁(yè)代碼
<template> <div class="common-layout"> <el-container> <!-- 側(cè)邊欄菜單 --> <el-aside width="auto"> <nav-menu :collpase="state.isCollapse"/> </el-aside> <el-container> <el-header> <nav-header v-model:collpase="state.isCollapse" /> </el-header> <el-main>Main</el-main> </el-container> </el-container> </div> </template> <script setup lang='ts'> import {ref, reactive } from 'vue' import NavMenu from '@/components/navMenu/index.vue' import NavHeader from '@/components/navHeader/index.vue' const state = reactive({ // 控制折疊與展開(kāi) isCollapse: false }) </script> <style scoped lang="scss"> .common-layout { width: 100%; height: 100%; .el-container { height: 100%; // 就是不折疊的時(shí)候?qū)挾仁?00px,折疊的時(shí)候?qū)挾茸赃m應(yīng) } } svg { width: 1em; height: 1em; margin-right: 5px; } </style>
nav-menu組件,側(cè)邊菜單組件代碼
<template> <el-menu default-active="2" class="el-menu-vertical-demo" :collapse="props.collpase" > <el-menu-item index="1"> <el-icon-menu /> <template #title>圖標(biāo)選擇器</template> </el-menu-item> <el-menu-item index="2"> <el-icon-aim /> <template #title>省市區(qū)組件</template> </el-menu-item> <el-menu-item index="3"> <el-icon-star /> <template #title>待定</template> </el-menu-item> </el-menu> </template> <script setup lang='ts'> const props = defineProps<{ collpase: boolean }>() </script> <style scoped lang="scss"> svg { width: 1em; height: 1em; margin-right: 5px; } // 記得要有這個(gè),控制側(cè)邊菜單寬度,意思是折疊的時(shí)候,寬度自適應(yīng),不著折疊的時(shí)候?qū)挾葹?00px .el-menu-vertical-demo:not(.el-menu--collapse) { width: 200px; min-height: 400px; } .el-menu { height: 100%; } </style>
nav-header組件的代碼
<template> <div class="collapse" @click="handleCollapse"> <el-icon-expand v-if="props.collpase"></el-icon-expand> <el-icon-fold v-else></el-icon-fold> </div> </template> <script setup lang='ts'> const props = defineProps<{ collpase: boolean }>() const emits = defineEmits<{ // 這樣寫,父組件通過(guò)v-model傳值進(jìn)來(lái),父組件那邊就不用在定義事件改變這里傳過(guò)去的值了 // update:collpase 就會(huì)自動(dòng)改變v-model傳過(guò)來(lái)的值了 (e:'update:collpase', value:boolean):void }>() const handleCollapse = ()=>{ emits('update:collpase', !props.collpase) } </script> <style scoped lang="scss"> .collapse { width: 2em; svg { width: 2em; height: 2em; } } </style>
以上是基于vue3 vite element-plus搭建的,值的注意的時(shí)候,里面的圖標(biāo)組件是經(jīng)過(guò)處理的,所以使用起來(lái),回和常規(guī)使用不一樣,將el-icon-xx替換為常規(guī)的element-plus圖標(biāo)組件使用方式即可
- 去除Element-Plus下拉菜單邊框的實(shí)現(xiàn)步驟
- 詳解vue3+element-plus實(shí)現(xiàn)動(dòng)態(tài)菜單和動(dòng)態(tài)路由動(dòng)態(tài)按鈕(前后端分離)
- vue3+element-plus動(dòng)態(tài)路由菜單示例代碼
- Vue3 Element-plus el-menu無(wú)限級(jí)菜單組件封裝過(guò)程
- Vue3+Element-Plus?實(shí)現(xiàn)點(diǎn)擊左側(cè)菜單時(shí)顯示不同內(nèi)容組件展示在Main區(qū)域功能
- Vue3+Element-Plus實(shí)現(xiàn)左側(cè)菜單折疊與展開(kāi)功能示例
- vue3使用element-plus搭建后臺(tái)管理系統(tǒng)之菜單管理功能
- element-plus默認(rèn)菜單打開(kāi)步驟
相關(guān)文章
vue框架和react框架的區(qū)別以及各自的應(yīng)用場(chǎng)景使用
這篇文章主要介紹了vue框架和react框架的區(qū)別以及各自的應(yīng)用場(chǎng)景使用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10關(guān)于SpringBoot與Vue交互跨域問(wèn)題解決方案
最近在利用springboot+vue整合開(kāi)發(fā)一個(gè)前后端分離的個(gè)人博客網(wǎng)站,所以這一篇總結(jié)一下在開(kāi)發(fā)中遇到的一個(gè)問(wèn)題,關(guān)于解決在使用vue和springboot在開(kāi)發(fā)前后端分離的項(xiàng)目時(shí),如何解決跨域問(wèn)題。在這里分別分享兩種方法,分別在前端vue中解決和在后臺(tái)springboot中解決。2021-10-10Vuejs第七篇之Vuejs過(guò)渡動(dòng)畫案例全面解析
這篇文章主要介紹了Vuejs第七篇之Vuejs過(guò)渡動(dòng)畫案例全面解析的相關(guān)資料,需要的朋友可以參考下2016-09-09vue兩組件間值傳遞 $router.push實(shí)現(xiàn)方法
兩組件間傳值,可能包含多種情況,這篇文章主要介紹了vue兩組件間值傳遞 $router.push實(shí)現(xiàn)方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-05-05Vue3源碼分析組件掛載創(chuàng)建虛擬節(jié)點(diǎn)
這篇文章主要為大家介紹了Vue3源碼分析組件掛載創(chuàng)建虛擬節(jié)點(diǎn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10vue使用swiper實(shí)現(xiàn)中間大兩邊小的輪播圖效果
這篇文章主要介紹了vue使用swiper實(shí)現(xiàn)中間大兩邊小的輪播圖效果,本文分步驟通過(guò)實(shí)例代碼講解的非常詳細(xì),需要的朋友可以參考下2019-11-11