<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="./lib/vue.js"></script>
<script src="./lib/vue-router.js"></script>
</head>
<style>
.header {
font-size: 16px;
width: 100%;
color: #fff;
text-align: center;
background-color: red;
padding: 10px 0;
margin: 0;
}
.box {
display: flex;
}
.leftBox {
flex: 2;
height: 500px;
color: #fff;
background-color: rosybrown;
margin: 0;
}
.mainBox {
flex: 8;
height: 500px;
color: #fff;
background-color: slateblue;
margin: 0;
}
</style>
<body>
<div id="app">
<router-view></router-view>
<div class="box">
<router-view name="left"></router-view>
//只需要添加name屬性就會去匹配相應的名字的組件
<router-view name="main"></router-view>
</div>
</div>
<script>
// 組件
var header = {
template: "<h3 class='header'>header頭部區域</h3>"
}
var leftBox = {
template: "<h3 class='leftBox'>left區域</h3>"
}
var mainBox = {
template: "<h3 class='mainBox'>main區域</h3>"
}
//路由規則
var router = new VueRouter({
routes: [
{
path: '/', components: {
//components加s表示有多個組件,他為一個對象
'default': header,
//表示默認的情況下顯示
'left': leftBox,
// 頁面中占位符,中的name要與字符串(left名字隨便起)一樣 leftBox表示組件名
'main': mainBox,
// 頁面中占位符,中的name要與字符串(left名字隨便起)一樣 leftBox表示組件名
}
}
]
})
var vm = new Vue({
el: "#app",
data: {},
methods: {},
router: router
})
</script>
</body>
</html>