【Vue.js】利用组件实现后台管理布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue组件实现后台布局</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
ul,
li {
list-style: none;
}
.layout {
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
}
.header {
width: 100%;
height: 60px;
background-color: blueviolet;
}
.main {
width: 100%;
flex: 1;
display: flex;
}
.menu-container {
width: 200px;
height: 100%;
background-color: chartreuse;
}
.right-container {
flex: 1;
height: 100%;
overflow: auto;
background-color: coral;
}
</style>
</head>
<body>
<template id="layout">
<div class="layout">
<u-header></u-header>
<div class="main">
<u-menu></u-menu>
<u-right></u-right>
</div>
</div>
</template>
<template id="header">
<header class="header">
头部信息
</header>
</template>
<template id="menu">
<aside class="menu-container">
<ul>
<li>菜单管理</li>
<li>系统管理</li>
</ul>
</aside>
</template>
<template id="right">
<header class="right-container">
右边功能区域
</header>
</template>
<div id="app"></div>
<script>
const UHeader = {
template: '#header'
}
const UMenu = {
template: '#menu'
}
const URight = {
template: '#right'
}
const appCmp = {
template: '#layout',
components: {
UHeader,
UMenu,
URight
}
}
new Vue({
el: '#app',
template: '<app></app>',
components: {
app: appCmp
}
})
</script>
</body>
</html>