当前位置: 首页 > news >正文

element plus中menu菜单技巧

我在使用element plus的menu(侧边栏)组件的过程中遇到了一些问题,就是menu编写样式和路由跳转,下面给大家分享以下,我是怎么解决的。

1.页面效果

我要实现的网站布局是这样的:

 侧边栏折叠以后的效果:

网站的布局我是用element plus官网提供的布局方式:

 2.样式

下面是对应的style设置:

这里我用了tailwind css。

3.路由

4.路由对应的页面

1.HomeView.vue

2.AboutView.vu

3.LayoutView.vue

<script setup>
import { Expand, Fold, HomeFilled, InfoFilled } from "@element-plus/icons-vue";
import {ref} from "vue";const isSidebarOpen = ref(false)</script><template><div class="common-layout"><el-container><el-aside :class="{'is-sidebar-open':isSidebarOpen}" width="200px" class="bg-gray-800 h-screen"><!--最上面logo--><div class="-ml-2 h-16 flex items-center justify-center"><img class="object-cover h-14 w-14" src="@/assets/images/A%20拷贝.png" alt="logo"><h1 v-show="!isSidebarOpen" class="-ml-2 text-2xl text-white font-bold">Blog</h1></div><el-menu:collapse="isSidebarOpen":collapse-transition="false"router:default-active="$route.path"background-color="#1f2937"text-color="#fff"style="border: none"><el-menu-item index="/home" route="/home"><el-icon><HomeFilled /></el-icon><span class="font-semibold">Home</span></el-menu-item><el-menu-item index="/about" route="/about"><el-icon><InfoFilled /></el-icon><span class="font-semibold">About</span></el-menu-item></el-menu></el-aside><el-container><el-header class="h-16 shadow-md z-10 flex items-center justify-between"><div><button @click="isSidebarOpen = !isSidebarOpen"><el-icon><component :is="isSidebarOpen ? Expand : Fold"></component></el-icon></button></div><div class="flex items-center space-x-4"><h1 class="font-medium">AkbarSmile</h1><img class="w-10 h-10 rounded-full" src="@/assets/images/Mofei1-cut.jpg" alt="avatar"></div></el-header><el-main class="bg-slate-100"><router-view></router-view></el-main></el-container></el-container></div>
</template><style scoped>
aside {@apply transition-all duration-300;
}
.is-sidebar-open {@apply w-16;
}.el-menu {@apply w-full
}
.el-menu--collapse .el-menu-item {@apply p-0 m-0 flex items-center justify-center;
}
.el-menu-item.is-active {@apply bg-purple-600 text-white w-full ;
}
</style>

可能很多同学没有使用过tailwind css,但是用普通的css代码,也可以实现同样的效果。

大家自己打开多研究研究,其实能找到找技巧的话,element plus非常好用。

http://www.lryc.cn/news/464232.html

相关文章:

  • 数据结构-贪心算法笔记
  • 基于SpringBoot的在线汽车票预订平台
  • ubuntu 安装nginx
  • fanuc远程PNS启动
  • 使用 Spring 框架构建 MVC 应用程序:初学者教程
  • 集成Spring Security详解
  • Kettle9.4支持Clickhouse数据源插件开发以及性能测试
  • 微信支付V3 yansongda/pay 踩坑记录
  • AndroidStudio实验报告——实验一、二
  • Nginx超简洁知识:负载均衡-反向代理,动静分离,配置文件
  • 云手机:社交平台运营的热门工具
  • iptables限速规则
  • 易泊车牌识别:海外车牌快速定制,开启智能识别新时代
  • 同一个交换机不同vlan的设备为什么不能通信
  • 《业务三板斧:定目标、抓过程、拿结果》读书笔记4
  • PRCV 2024 - Day2
  • 大厂面试真题-了解云原生吗,简单说一下docker和k8s
  • Python基础入门
  • 深入了解路由
  • 三大编程思想(POP、OOP、AOP、FOP)及oop 五大设计原则
  • JavaWeb开发4
  • Git中Update和Pull的区别
  • 物理安全概述
  • 引领智慧文旅新纪元,开启未来旅游新境界
  • Qt开发技巧(十七):新窗口控件用智能指针,将一些配置类变量封装起来,Qt窗体的Z序叠放,子窗体的释放,Qt中的事件发送,Qt的全局头文件
  • 5G 现网信令参数学习(1) - MIB
  • stm32单片机个人学习笔记9(TIM输入捕获)
  • ubuntu 安装haproxy
  • TF-A(Trusted Firmware-A)及其启动流程详解:以stm32MP1平台为例
  • FL Studio 2024 发布,添加 FL Cloud 插件、AI 等功能