1.0.0 • Published 3 months ago

@ssmt-ui/el-sidebar v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

@ssmt-ui/el-sidebar

基于 Element UI 的侧边栏菜单组件,支持多级菜单、折叠展开等功能。

安装

npm install @ssmt-ui/el-sidebar

使用

<template>
  <el-sidebar
    :menu-data="menuData"
    :active-menu="activeMenu"
    :is-collapse="isCollapse"
    @select="handleSelect"
  />
</template>

<script>
import { ElSidebar } from '@ssmt-ui/el-sidebar';

export default {
  components: {
    ElSidebar
  },
  data() {
    return {
      menuData: [
        {
          title: '首页',
          path: '/home',
          icon: 'el-icon-home'
        },
        {
          title: '系统管理',
          path: '/system',
          icon: 'el-icon-setting',
          children: [
            {
              title: '用户管理',
              path: 'user'
            },
            {
              title: '角色管理',
              path: 'role'
            }
          ]
        }
      ],
      activeMenu: '/home',
      isCollapse: false
    };
  },
  methods: {
    handleSelect(key, keyPath) {
      console.log('选中菜单:', key, keyPath);
    }
  }
};
</script>

Props

参数说明类型默认值
menuData菜单数据Array-
activeMenu当前激活菜单的 pathstring''
isCollapse是否水平折叠收起菜单booleanfalse
backgroundColor菜单的背景色string'#545c64'
textColor菜单的文字颜色string'#fff'
activeTextColor当前激活菜单的文字颜色string'#ffd04b'
uniqueOpened是否只保持一个子菜单的展开booleanfalse
collapseTransition是否开启折叠动画booleantrue
mode模式string'vertical'

Events

事件名称说明回调参数
select菜单选中时触发key: 选中菜单项的 path, keyPath: 选中菜单项的路径数组

menuData 数据结构

interface MenuItem {
  title: string;      // 菜单标题
  path: string;       // 菜单路径
  icon?: string;      // 菜单图标(element-ui 的图标类名)
  children?: MenuItem[]; // 子菜单
}

依赖

  • Vue 2.6+
  • Element UI 2.15+

License

MIT

1.0.0

3 months ago