<!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>
原文地址:https://www.cnblogs.com/Progress-/p/12209170.html