惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
爱范儿
爱范儿
人人都是产品经理
人人都是产品经理
博客园 - 司徒正美
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
量子位
罗磊的独立博客
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
小众软件
小众软件
C
Cybersecurity and Infrastructure Security Agency CISA
Cyberwarzone
Cyberwarzone
大猫的无限游戏
大猫的无限游戏
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
博客园 - 三生石上(FineUI控件)
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园_首页
博客园 - 叶小钗
V
Vulnerabilities – Threatpost
T
The Exploit Database - CXSecurity.com
T
Tailwind CSS Blog
IT之家
IT之家
博客园 - 聂微东
Spread Privacy
Spread Privacy
V2EX - 技术
V2EX - 技术
S
Security Affairs
宝玉的分享
宝玉的分享
V
V2EX
C
Cisco Blogs
博客园 - Franky
美团技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
月光博客
月光博客
S
Securelist
J
Java Code Geeks
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
WordPress大学
WordPress大学
W
WeLiveSecurity
T
Threatpost
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志

博客园 - 一丝心情

Volta 安装和使用指南 免费国产ai试用总结 glb格式3d模型压缩 nuxt.js 项目流水线自动部署设置 免费的云数据库 vue 实用指令 IntelliJ IDEA license server 激活(亲测有效) win10/win11专业版激活码(亲测有效) Git 常用指令完全指南 npm 安装依赖报错整理 css3文字渐变, svg文字渐变 http/https与websocket的ws/wss的关系 指令 v-tooltip vue 自定义指令实现v-overflow-tooltip 常用css vue.config.js config.resolve.alias 目录别名配置 three.js 在低版本浏览报THREE.WebGLProgran: shader error 报错解决办法 nuxt 低版本浏览器兼容babel编译配置 常用软件历史版本下载 前端常用指令 数组常用方法总结 vue 中 echarts 添加事件 常用正则
element-ui NavMenu 多级嵌套封装
一丝心情 · 2023-05-17 · via 博客园 - 一丝心情
  1. 安装依赖引用依赖
    /* 安装依赖 */
    // 安装element-ui
    npm i element-ui -S
    // 安装vue-fragment
    npm i -s vue-fragment
    
    
    /* main.js 引入 */
    import Vue from 'vue';
    // 引用element-ui
    import ElementUI from 'element-ui';
    import 'element-ui/lib/theme-chalk/index.css';
    // 引用vue-fragment
    import { Plugin } from 'vue-fragment'
    Vue.use(Plugin)
  2. SidebarItem 组件封装
    <template>
        <fragment v-if="!item.hidden">
            <el-submenu
                v-if="item.children && item.children.length"
                :index="item.label"
            >
                <template slot="title">
                    <i :class="item.icon"/>
                    {{ item.label }}
                </template>
    
                <sidebar-item
            v-for="child in item.children"
                    @item-click="(i) => $emit('item-click', i)"
            :key="child.path"
            :item="child"
          />
            </el-submenu>
    
            <el-menu-item
                v-else
                :index="item.url"
                @click="$emit('item-click', item)">
                <i :class="item.icon"/>
                {{ item.label }}
            </el-menu-item>
        </fragment>
    </template>
    
    <script>
    export default {
      name: 'SidebarItem',
      props: {
        item: {
          type: Object,
          required: true
        }
      },
      methods: {
        handleItemClick (item) {
          this.$emit('item-click', item)
        }
      }
    }
    </script>
  3. SidebarItem组件应用
    <template>
      <el-menu :default-active="activeIndex" unique-opened @select="handleLoadUrl">
        <sidebar-item v-for="item in menuList" :key="item.path" :item="item" @item-click="handleItemClick"/>
      </el-menu>
    </template>
    
    <script>
    import SidebarItem from './sidebarItem.vue'
    export default {
      components: { SidebarItem },
      data () {
        return {
          activeIndex: '/1',
          menuList: [
            {
              label: '一级菜单1',
              icon: 'el-icon-s-help',
              url: '/1'
            },
            {
              label: '一级菜单2',
              icon: 'el-icon-s-help',
              url: '/2',
              children: [
                  { label: '二级菜单2.1', url: '/2/1' }
              ]
            }
          ]
        }
      },
      watch: {
        $route: {
          handler: function (to, from) {
            this.$nextTick(() => {
              if (to) {
                this.activeIndex = to.path
              }
            })
            // console.log(to, from)
          },
          immediate: true
        }
      },
      created () {
      },
      mounted () {},
      methods: {
        handleLoadUrl (index, indexPath) {
          // console.log(index, indexPath, 5566)
        },
        handleItemClick (item) {
          const { url, label } = item
          this.activeIndex = url || label
          this.$router.push(this.activeIndex)
        }
      }
    }
    </script>
  4. .....