<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="vue.js"></script>
<script src="vue-router.js"></script>
<style>
.index{
height:900px;
background-color: red
}
.list{
height:1800px;
background-color: green
}
</style>
</head>
<body>
<div id="app">
<router-view></router-view>
<router-link to="/">index</router-link>
<router-link to="/list">list</router-link>
{{flag}}
</div>
</body>
<script>
var index={
data:function(){
return{
name:"jay"
}
},
// beforeRouteEnter:function(to,from,next){
// setTimeout(function(){
// next(function(vm){
// vm.name="jay"
// });
// },2000)
// },
beforeRouteLeave:function(to,from,next){
console.log("update");
next();
},
template:"<h1 class='index'>{{name}}</h1>"
}
var list={
template:"<h1 class='list'>list</h1>"
}
var app=new Vue({
el:"#app",
data:{
flag:false
},
created:function(){
this.$router.beforeEach(function(to,from,next){
// window.scrollTo(0,0);
document.documentElement.scrollTop=0;
next();
})
},
router:new VueRouter({
routes:[
{
path:"/",
component:index
},
{
path:"/list",
component:list
}
]
})
})
</script>
</html>
网友评论