组件嵌套
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- 引入vue.js -->
<script src="./vue.js"></script>
<style>
*{
margin: 0;
padding: 0;
list-style: none;
}
.container{
width:100vw;
height: 100vh;
background: grey;
display: flex;
flex-direction: column;
}
.header{
height:100px;
background: greenyellow;
}
.main{
flex:1;
background: tomato;
display: flex;
}
.left{
width: 200px;
background: turquoise;
}
.right{
flex:1;
}
.footer{
height:100px;
background: yellowgreen;
}
</style>
</head>
<body>
<!-- 作用域 -->
<div id="app">
</div>
<!-- 标签模板 page组件 -->
<template id="page">
<div class="container">
<v-header></v-header>
<v-main></v-main>
<v-footer></v-footer>
</div>
</template>
<!-- 标签模板 header组件 -->
<template id="header">
<div class="header">
header
</div>
</template>
<!-- 标签模板 main组件 -->
<template id="main">
<div class="main">
<v-left></v-left>
<v-right></v-right>
</div>
</template>
<!-- 标签模板 footer组件 -->
<template id="footer">
<div class="footer">
footer
</div>
</template>
<!-- 标签模板 left组件 -->
<template id="left">
<div class="left">
left
</div>
</template>
<!-- 标签模板 right组件 -->
<template id="right">
<div class="right">
right
</div>
</template>
<script>
const vLeft = {
template:'#left'
}
const vRight = {
template:'#right'
}
const vHeader = {
template:'#header'
}
const vMain = {
template:'#main',
components:{
// 左侧组件
vLeft,
//右侧组件
vRight,
}
}
const vFooter = {
template:'#footer'
}
const vPage = {
template:'#page',
components:{
// 头部组件
vHeader,
// 中间组件
vMain,
// 底部组件
vFooter,
}
}
// 实例化vue
new Vue({
el:'#app',
data:{},
methods:{},
components:{
vPage
},
template:'<v-page></v-page>',
})
</script>
</body>
</html>