vue+element 导航 实现例子

项目使用的是 vue 3,安装配置可以查看栏目前面的文章。

组件

导航:https://element-plus.org/zh-CN/component/menu.html

面包屑:https://element-plus.org/zh-CN/component/breadcrumb.html

安装element库

shell 复制代码
PS D:\code\my-vue3-project>  npm install element-plus --save

added 23 packages, and audited 57 packages in 17s

11 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

运行后,项目package.json文件添加了依赖:

js 复制代码
"dependencies": {
    "element-plus": "^2.9.9",
    ...
   },

代码中导入依赖

在main.js中import 相关依赖

js 复制代码
import { createApp } from 'vue'
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import './style.css'
import App from './App.vue'

没导入css,会导致组件的样式不正确。

添加侧边导航实现

导入组件

在.vue文件中导入用到的组件:

js 复制代码
<script>
import { ElRow, ElCol, ElMenu,ElSubMenu, 
  ElMenuItem, ElMenuItemGroup,ElIcon } from 'element-plus'
...
</script>

导航实现

js 复制代码
<template>
 <el-row class="tac">
    <el-col>
      <h5 class="mb-2">Default colors</h5>
      <el-menu
        default-active="2"
        class="el-menu-vertical-demo"
        @open="handleOpen"
        @close="handleClose"
      >
        <el-sub-menu index="1">
          <template #title>
            <el-icon><location /></el-icon>
            <span>Navigator One</span>
          </template>
          <el-menu-item-group title="Group One">
            <el-menu-item index="1-1">item one</el-menu-item>
            <el-menu-item index="1-2">item two</el-menu-item>
          </el-menu-item-group>
          <el-menu-item-group title="Group Two">
            <el-menu-item index="1-3">item three</el-menu-item>
          </el-menu-item-group>
          <el-sub-menu index="1-4">
            <template #title>item four</template>
            <el-menu-item index="1-4-1">item one</el-menu-item>
          </el-sub-menu>
        </el-sub-menu>
        <el-menu-item index="2">
          <el-icon><icon-menu /></el-icon>
          <span>Navigator Two</span>
        </el-menu-item>
        <el-menu-item index="3" disabled>
          <el-icon><document /></el-icon>
          <span>Navigator Three</span>
        </el-menu-item>
        <el-menu-item index="4">
          <el-icon><setting /></el-icon>
          <span>Navigator Four</span>
        </el-menu-item>
      </el-menu>
    </el-col>
   
  </el-row>
</template>

上面的代码是从官方上复制过来,删除了长度限制":span="12""

运行

npm run dev

源码:https://download.csdn.net/download/xgw1010/90762342

相关推荐
Attacking-Coder23 分钟前
前端面试宝典---前端水印
前端
姑苏洛言3 小时前
基于微信公众号小程序的课表管理平台设计与实现
前端·后端
烛阴3 小时前
比UUID更快更小更强大!NanoID唯一ID生成神器全解析
前端·javascript·后端
Alice_hhu3 小时前
ResizeObserver 解决 echarts渲染不出来,内容宽度为 0的问题
前端·javascript·echarts
charlee444 小时前
解决Vditor加载Markdown网页很慢的问题(Vite+JS+Vditor)
javascript·markdown·cdn·vditor
逃逸线LOF4 小时前
CSS之动画(奔跑的熊、两面反转盒子、3D导航栏、旋转木马)
前端·css
老马啸西风5 小时前
工作流引擎-18-开源审批流项目之 plumdo-work 工作流,表单,报表结合的多模块系统
vue.js·开源·activiti·workflow·flowable·oa·bpm
萌萌哒草头将军5 小时前
⚡️Vitest 3.2 发布,测试更高效;🚀Nuxt v4 测试版本发布,焕然一新;🚗Vite7 beta 版发布了
前端
技术小丁5 小时前
使用 HTML + JavaScript 在高德地图上实现物流轨迹跟踪系统
前端·javascript·html
小小小小宇6 小时前
React 并发渲染笔记
前端