首页 > 其他分享 >Vue3+Elementplus 递归菜单展示

Vue3+Elementplus 递归菜单展示

时间:2024-07-19 10:18:37浏览次数:7  
标签:Elementplus const value label 菜单 Vue3 import children

这里只是做个笔记,js,css那些都没写

子组件 MenuItem

<template>
  <template v-if="item.children">
    <el-sub-menu :index="item.value">
      <template #title>{{ item.label }}</template>
      <MenuItem v-for="childItem in item.children" :key="childItem.value" :item="childItem" />
    </el-sub-menu>
  </template>
  <template v-else>
    <el-menu-item :index="item.value">{{ item.label }}</el-menu-item>
  </template>
</template>
<script setup>
import { defineProps } from 'vue';
 defineProps(['item']);
</script>
<style scoped>
</style>

父组件,调用

<template>
  <el-menu
      :default-active="activeIndex"
      class="el-menu-vertical-demo"
      @select="handleSelect"
      background-color="#f8f8f9"
      style="margin-top: 20px;margin-left: 1px;width: 20%"
  >
    <MenuItem v-for="menuItem in menuItems" :key="menuItem.value" :item="menuItem" />
  </el-menu>
</template>
<script setup>
import MenuItem from "./components/MenuItem.vue";
import {ref} from "vue";
const menuItems = [
  {
    value: '1',
    label: '菜单1',
    children: [
      {
        value: '1-1',
        label: '子菜单1-1',
        children: [
          { value: '1-1-1', label: '子菜单1-1-1' },
          { value: '1-1-2', label: '子菜单1-1-2' },
        ],
      },
      { value: '1-2', label: '子菜单1-2' },
    ],
  },
  {
    value: '2',
    label: '菜单2',
    children: [
      { value: '2-1', label: '子菜单2-1' },
      {
        value: '2-2',
        label: '子菜单2-2',
        children: [
          { value: '2-2-1', label: '子菜单2-2-1' },
          { value: '2-2-2', label: '子菜单2-2-2' },
        ],
      },
    ],
  },
  {
    value: '3',
    label: '菜单3',
    children: [
      {
        value: '3-1',
        label: '子菜单3-1',
        children: [
          {
            value: '3-1-1',
            label: '子菜单3-1-1',
            children: [
              { value: '3-1-1-1', label: '子菜单3-1-1-1' },
              { value: '3-1-1-2', label: '子菜单3-1-1-2' },
            ],
          },
        ],
      },
    ],
  },
];
const activeIndex = ref(1)
const handleSelect = async (key, keyPath) => {
  console.log(key, keyPath)
  this.activeIndex = key
}
</script>

标签:Elementplus,const,value,label,菜单,Vue3,import,children
From: https://www.cnblogs.com/qcy-blog/p/18310912

相关文章

  • ts vue3 定义props写法参考
    写法1exportinterfaceConfig{arr1:Array<IObject>,obj1?:IObject}constprops=defineProps({title:{type:String, //必须的proprequired:true,default:'DefaultTitle'},//数组dicts:{type:Array,requ......
  • vue3 使用component is 动态组件
    使用方式父组件<template><divclass="box"><div><!--setup需要用变量的方式来写入is,如果是optionsapi方式可以用组件字符--><!--myProps属性可以直接传到动态组件--><component:is="childT"myProps="sldfjsklfjksf......
  • vue3 watch watchEffect computed 使用差别
    概论watch监听明确的数据computed监听数据并返回计算结果watchEffect重视监听过程测试代码子组件<template><divclass='box'><div>props监听测试</div>computed返回的内容的深度属性:{{configTwo.obj1&&configTwo.obj1.xxx}}<div></div......
  • Vue3动态生成组件
    在Vue3中,要遍历funConfig并动态生成组件,可以使用Vue的defineAsyncComponent来加载异步组件,并结合v-for指令在模板中进行渲染。以下是一个示例代码来实现这个需求:1.配置文件确保配置文件导出的是一个reactive对象:import{reactive}from'vue';exportconst......
  • Vue3学习---1
    Vue3学习1.初识Vue1.1HelloWorld程序<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><ti......
  • Windows 11开始菜单变了!应用分类显示 更好找
    Windows11重新设计了开始菜单,虽然备受争议,但其实也挺好用的,只是有一个槽点,安装了太多应用软件之后,滚动列表会非常长,很难找到自己需要的。在最新的Windows1122635.3930测试版本中,微软隐藏了一个新功能,尝试重新设计开始菜单的应用列表,增加了一个“类别”(Category)模式。在这......
  • vue3中使用@作为引用根目录报错
    在Vue3中使用 @ 作为引用根目录(通常是 src 目录)报错,通常是因为配置未正确设置或者配置未被项目正确识别。1.1.排查和解决此类问题的步骤:确认配置文件:对于使用Vite的项目,需要在 vite.config.ts 文件中配置路径别名。确保你已经正确导入了 path 模块,并设置了......
  • 自研electron31+vue3+elementPlus桌面聊天Exe应用-源码版
    Vue3-ElectronWechat:基于最新前端跨平台技术electron31.x整合高性能构建工具vite.js5搭建的一款高颜值桌面端仿微信界面聊天程序。整个项目采用vue3setup语法糖编码开发,全新封装electron多窗口管理模式。基于vite5+electron31+vue3仿微信客户端聊天【源码版】功能特......
  • [VUE3] 使用D3实现日历热力图
    开始最近我在写自己的网站,需要日历热度图来丰富点内容;所以在网上找了许多参考,如下:https://www.zzxworld.com/posts/draw-calendar-of-heatmap-chart-with-d3jshttps://github.com/DominikAngerer/vue-heatmap/blob/master/README.md将两个结合就是我想要的。现在是这样:代......
  • vue3 封装svg图标
    安装插件npmivite-plugin-svg-icons1.修改 vite.config.jsimport{resolve}from'path'import{createSvgIconsPlugin}from'vite-plugin-svg-icons';exportdefaultdefineConfig({  plugins:[    vue(),    createSvgIconsPlugin({......