Skip to content

侧边栏菜单 Menu

三级层叠侧边栏菜单

静态组件渲染

组件元素添加".open-menu-react"自适应样式,在小于960px的屏幕会自动隐藏到屏幕左侧

查看代码
html
<div class="open-container">
	<!-- 菜单组件 -->
    <div class="open-menu" id="menu">
        <ul class="open-menu-wrapper">
            <li class="open-menu-item">
                <a class="open-menu-link" href="/">
                    <p class="open-menu-title">
                        <span class="open-menu-icon"><i class="iconfont icon-shouye"></i></span>
                        <span class="open-menu-name">首页</span>
                    </p>
                </a>
            </li>
            <li class="open-menu-item">
                <a class="open-menu-link">
                    <p class="open-menu-title">
                        <span class="open-menu-icon"><i class="iconfont icon-lanmu"></i></span>
                        <span class="open-menu-name">栏目管理</span>
                    </p>
                    <span class="open-menu-icon-arrow"></span>
                </a>
                <ul class="open-submenu">
                    <li class="open-menu-item">
                        <a class="open-menu-link" >
                            <p class="open-menu-title">
                                <span class="open-menu-name">分类管理</span>
                            </p>
                            <span class="open-menu-icon-arrow"></span>
                        </a>
                        <ul class="open-submenu">
                            <li class="open-menu-item">
                                <a class="open-menu-link" href="#">
                                    <p class="open-menu-title">
                                        <span class="open-menu-name">视频管理</span>
                                    </p>
                                </a>
                            </li>
                            <li class="open-menu-item">
                                <a class="open-menu-link" href="#">
                                    <p class="open-menu-title">
                                        <span class="open-menu-name">图片管理</span>
                                    </p>
                                </a>
                            </li>
                        </ul>
                    </li>
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">标签管理</span>
                            </p>
                        </a>
                    </li>
                </ul>
            </li>
            <li class="open-menu-item">
                <a class="open-menu-link">
                    <p class="open-menu-title">
                        <span class="open-menu-icon"><i class="iconfont icon-neirong"></i></span>
                        <span class="open-menu-name">内容管理</span>
                    </p>
                    <span class="open-menu-icon-arrow"></span>
                </a>
                <ul class="open-submenu">
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">文章管理</span>
                            </p>
                        </a>
                    </li>
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">图片管理</span>
                            </p>
                        </a>
                    </li>
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">视频管理</span>
                            </p>
                        </a>
                    </li>
                </ul>
            </li>
            <li class="open-menu-item">
                <a class="open-menu-link">
                    <p class="open-menu-title">
                        <span class="open-menu-icon"><i class="iconfont icon-icon_hudong-mian"></i></span>
                        <span class="open-menu-name">互动管理</span>
                    </p>
                    <span class="open-menu-icon-arrow"></span>
                </a>
                <ul class="open-submenu">
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">评论管理</span>
                            </p>
                        </a>
                    </li>
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">点赞管理</span>
                            </p>
                        </a>
                    </li>
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">留言管理</span>
                            </p>
                        </a>
                    </li>
                </ul>
            </li>
            <li class="open-menu-item">
                <a class="open-menu-link">
                    <p class="open-menu-title">
                        <span class="open-menu-icon"><i class="iconfont icon-yingxiao_selected"></i></span>
                        <span class="open-menu-name">营销管理</span>
                    </p>
                    <span class="open-menu-icon-arrow"></span>
                </a>
                <ul class="open-submenu">
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">轮播图管理</span>
                            </p>
                        </a>
                    </li>
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">广告管理</span>
                            </p>
                        </a>
                    </li>
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">友情链接管理</span>
                            </p>
                        </a>
                    </li>
                </ul>
            </li>
             <li class="open-menu-item">
                <a class="open-menu-link">
                    <p class="open-menu-title">
                        <span class="open-menu-icon"><i class="iconfont icon-xitong"></i></span>
                        <span class="open-menu-name">系统管理</span>
                    </p>
                    <span class="open-menu-icon-arrow"></span>
                </a>
                <ul class="open-submenu">
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">网站信息</span>
                            </p>
                        </a>
                    </li>
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">数据备份</span>
                            </p>
                        </a>
                    </li>
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">SEO</span>
                            </p>
                        </a>
                    </li>
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">内容过滤</span>
                            </p>
                        </a>
                    </li>
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">系统日志</span>
                            </p>
                        </a>
                    </li>
                </ul>
            </li>
             <li class="open-menu-item">
                <a class="open-menu-link">
                    <p class="open-menu-title">
                        <span class="open-menu-icon"><i class="iconfont icon-guanliyuan"></i></span>
                        <span class="open-menu-name">管理员管理</span>
                    </p>
                    <span class="open-menu-icon-arrow"></span>
                </a>
                <ul class="open-submenu">
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">管理员管理</span>
                            </p>
                        </a>
                    </li>
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">角色管理</span>
                            </p>
                        </a>
                    </li>
                    <li class="open-menu-item">
                        <a class="open-menu-link" href="#">
                            <p class="open-menu-title">
                                <span class="open-menu-name">权限分类</span>
                            </p>
                        </a>
                    </li>
                </ul>
            </li>
        </ul>
    </div>
</div>

<script setup>
	import { onMounted } from 'vue'
	import openui from '../openui@0.1.0-beta/js/openui.esm.js'

	onMounted(()=>{
		
        const menu = openui.menu;

        // 静态渲染
        menu.renderStatic();
        
        // 监听点击事件
        menu.on({
            id: '#menu',
            click: function(res){
                console.log(res)
            }
        })
	})

</script>

API

API描述
menu.renderStatic()静态渲染
menu.on(id,()={})事件监听
menu.collapse(id);横向折叠菜单

静态渲染

menu.renderStatic()

默认会获取符合约定的组件dom模版进行渲染

事件监听

menu.on(id,(res)=>{})

js
// 静态组件,动态组件都会触发
// 返回当前点击菜单的href路径
menu.on(id,(url)=>{
	console.log(url)
})

横向折叠菜单

menu.collapse(id)

  • 执行此方法会往菜单组件添加一个样式
  • 在pc宽屏下菜单宽度会减少到50px左右,只保留图标的缩减菜单
  • 在移动端,会直接隐藏菜单到左侧
  • 重复执行此方法,会自动来回隐从屏幕左侧动画显示隐藏菜单
  • 如果需要支持响应式,菜单添加.open-menu-react响应式样式