首页 > 其他分享 >element-ui NavMenu 多级嵌套封装

element-ui NavMenu 多级嵌套封装

时间:2023-05-17 09:24:26浏览次数:28  
标签:vue url label item ui NavMenu element

  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. .....

标签:vue,url,label,item,ui,NavMenu,element
From: https://www.cnblogs.com/ysxq/p/17407522.html

相关文章

  • 动态加载UI文件
    1.对象名称要设置一样否则报错,请求不到窗口: 1_2.响应窗口请求成功: 3.修改界面样式后运行成功: 4.注意样式设计的名称要对应: 5.代码加载调用窗口: ......
  • 什么是 SAP UI5 Application Index
    SAPUI5ApplicationIndex是一个集成在SAPFioriLaunchpad中的应用程序索引。它提供了一个集中式的位置,用于展示和访问已安装的SAPUI5应用程序。在SAPFioriLaunchpad的主页上,用户可以看到一个应用程序索引页面,其中包含了所有已经安装的SAPUI5应用程序。这个索引页面提供了......
  • css 样式文件中的特殊符号 - 波浪号(也叫 tilde,squiggle,twiddle)
    例子:.check:checked~.content{}~选择器实际上是后继同胞组合器(在2017年之前称为一般同胞组合器):后继同胞组合器由“波浪号”(U+007E,~)字符组成,它将两个简单选择器序列分隔开。由这两个序列表示的元素在文档树中具有相同的父级,并且由第一个序列表示的元素位于由第二个序列表......
  • 使用 SAP Fiori Tools 提供的中间件导入本地下载的 SAP UI5 库文件来启动 SAP UI5 应
    本教程第100个步骤,笔者介绍了如何使用本地部署的SAPUI5库文件来运行SAPUI5应用的技巧:SAPUI5应用开发教程之一百-如何修改SAPUI5框架的源代码实现,以及使用本地部署的SAPUI5SDK我们简单回顾一下这种方法的实现步骤:从SAPUI5官网将我们想使用的SAPUI5SDK......
  • SAP UI5 Tooling - 在 i18n.properties 文件里维护中文字符后变成乱码该如何解决
    看这个Githubissue.重现步骤:解决方案settingthepropertiesFileSourceEncodingconfigurationinui5.yamltoUTF-8.Documentation:https://sap.github.io/ui5-tooling/pages/Configuration/#encoding-of-properties-filesExample:https://github.com/SAP-samples/ope......
  • 使用 SAP Fiori Tools 自带的代理服务器解决本地运行的 SAP UI5 应用访问远端服务遇到
    我们部署在本地开发环境运行的SAPUI5应用,由于浏览器安全策略的限制,无法直接访问远端OData服务,原因是我们的SAPUI5应用本地运行在localhost这个域名上,而远端请求的OData服务的域名比如说services.odata.org,二者不是同一个域名,由于浏览器安全策略,浏览器拒绝这种跨域的......
  • SAP UI5 应用的两种开发方式的教程
    要开发连接到SAPOData服务的SAPUI5应用程序,开发人员可以使用以下选项之一:SAPFioriElements这种方式基于常见业务场景的几个基本Floorplans创建标准应用程序。这些Floorplans提供UI代码,包括一些预置的逻辑,以便来自后端的数据准确地到达预期的位置,并且UI行为基于......
  • SAP UI5 Flexible Programming Model Explorer
    按照SAPUI5官网的说法,TheSAPUI5freestyletemplatesaredeprecated,andit’srecommendedtousethecustompageSAPFioritemplatebasedontheflexibleprogrammingmodelasanalternative.Formoreinformation,seeFlexibleProgrammingModelInformation......
  • 使用 SAP Fiori tools 开发 SAP UI5 应用
    SAPFioritools通过为SAPBusinessApplicationStudio和VSCode开发环境提供扩展功能,简化了SAPFioriElements应用程序的开发。SAPFioritools扩展功能可帮助开发人员创建应用程序、可视化导航、自动生成代码等。结合SAPFioriElements使用,这些扩展可以提高开发效......
  • SAP Fiori Elements 本地应用启动的三种模式辨析试读版
    本教程前一步骤,我们介绍了在VisualStudioCode里使用命令行npmrunstart启动SAPFioriElements应用的方法:3.动手运行第一个SAPFioriElements应用有细心的学习者发现了,笔者提供的这个FioriElements应用的package.json文件的scripts区域里,除了定义了名为st......