Vue开发实例实现左侧菜单导航
<template>
<div class="side-nav">
<el-menu
default-active="2"
class="el-menu-vertical-demo"
@open="handleOpen"
@close="handleClose"
unique-opened
>
<el-submenu index="1">
<template slot="title">
<i class="el-icon-location"></i>
<span>导航一</span>
</template>
<el-menu-item index="1-1">选项1</el-menu-item>
<el-menu-item index="1-2">选项2</el-menu-item>
</el-submenu>
<el-menu-item index="2">
<i class="el-icon-menu"></i>
<span slot="title">导航二</span>
</el-menu-item>
<el-menu-item index="3" disabled>
<i class="el-icon-document"></i>
<span slot="title">导航三</span>
</el-menu-item>
<el-menu-item index="4">
<i class="el-icon-setting"></i>
<span slot="title">导航四</span>
</el-menu-item>
</el-menu>
</div>
</template>
<script>
export default {
methods: {
handleOpen(key, keyPath) {
console.log('菜单项打开', key, keyPath);
},
handleClose(key, keyPath) {
console.log('菜单项关闭', key, keyPath);
}
}
}
</script>
<style>
.side-nav {
height: 100%;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
width: 200px;
min-height: 400px;
}
</style>
这个代码实例使用了Element UI库中的<el-menu>
和<el-submenu>
组件来创建一个左侧的导航菜单。菜单项可以被打开和关闭,并且提供了两个方法handleOpen
和handleClose
来处理这些事件。这个例子展示了如何使用Vue和Element UI来构建一个功能完整的左侧菜单导航。
评论已关闭