代码拉取完成,页面将自动刷新
<!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>
<style>
.header{
background-color: orange;
height: 80px;
}
.container{
display: flex;
height: 100px;
}
.left{
background-color: lightcoral;
flex: 2;
}
.main{
background-color: lightblue;
flex: 8;
}
h1{
margin: 0;
padding: 0;
font-size: 40px;
}
html, body{
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="app">
<h2>
<router-link to="/2">header</router-link>
<router-link to="/user/1">user</router-link>
</h2>
<router-view></router-view>
<div class="container">
<router-view name='left'></router-view>
<router-view name='main'></router-view>
</div>
</div>
<template id="user">
<div>
<h1>User:{{$route.params.id}}</h1>
<h1>使用props传参:{{id}}</h1>
</div>
</template>
<script>
var header = {
template: '<h1 class="header">header头部区域:{{id}}</h1>',
props:['id']
}
var leftBox = {
template: '<h1 class="left">Left侧边栏:{{id}}</h1>',
props:['id']
}
var mainBox = {
template: '<h1 class="main">mainBox头部区域:{{id}}</h1>',
props:['id']
}
const User = {
template:'#user',
props:['id']
}
var router = new VueRouter({
routes: [
/*
{path: '/', component: header},
{path: '/left', component: leftBox},
{path: '/main', component:mainBox},
*/
// 对于包含命名视图的路由,你必须分别为每个命名视图添加 `props` 选项:
{path:'/:id', components: {
'default': header,
'left': leftBox,
'main': mainBox
},
props:{default:true,left:false,main:true}
},
// 如果 props 被设置为 true,route.params 将会被设置为组件属性。
{path:'/user/:id',component:User,props:true}
]
})
var vm = new Vue({
el: '#app',
data: {
},
methods: {
},
router
})
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。