3分钟学会搭建动态侧边栏导航:Vue + Element-UI
<template>
<el-container style="height: 500px; border: 1px solid #eee">
<el-aside width="200px" style="background-color: rgb(238, 241, 246)">
<el-menu :default-openeds="defaultOpeneds" :default-active="defaultActive" @open="handleOpen" @close="handleClose">
<el-submenu index="1">
<template slot="title">
<i class="el-icon-message"></i>导航一
</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>
</el-aside>
<el-main>
<el-table :data="tableData" style="width: 100%">
<el-table-column prop="date" label="日期" width="180"></el-table-column>
<el-table-column prop="name" label="姓名" width="180"></el-table-column>
<!-- 其他表格列配置 -->
</el-table>
</el-main>
</el-container>
</template>
<script>
export default {
data() {
return {
defaultOpeneds: ['1'],
defaultActive: '1-1',
tableData: [
{ date: '2016-05-02', name: '王小虎' },
{ date: '2016-05-04', name: '李小虎' }
// 其他数据
]
};
},
methods: {
handleOpen(key, keyPath) {
console.log('open: ', key, keyPath);
},
handleClose(key, keyPath) {
console.log('close: ', key, keyPath);
}
}
};
</script>
<style>
.el-container {
padding: 0;
}
.el-header,
.el-footer {
background-color: #b3c0d1;
color: var(--el-text-color-primary);
text-align: center;
line-height: 60px;
}
.el-aside {
background-color: #d3dce6;
color: var(--el-text-color-primary);
text-align: center;
line-height: 200px;
}
.el-main {
background-color: #e9eef3;
color: var(--el-text-color-primary);
text-align: center;
line-height: 160px;
}
body > .el-container {
margin-bottom: 40px;
}
.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
line-height: 260px;
}
.el-container:nth-child(7) .el-aside {
line-height: 320px;
}
</style>
这段代码使用Vue和Element-UI创建了一个带有侧边栏导航的管理界面样板。侧边栏中有一个可折叠的导航菜单,以及一个主要区域显示表格数据。通过这个示例,开发者可以快速了解如何利用Element-UI组件库搭建动态的管理界面。
评论已关闭