美文网首页
滚动行为

滚动行为

作者: 嗯哼_3395 | 来源:发表于2018-07-07 16:00 被阅读0次
<!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>

相关文章

  • Js实现鼠标滚轮滑动监听

    监听鼠标滚动行为 禁止、启用鼠标滚动行为

  • 滚动行为

  • 滚动行为

    滚动行为 应用场景 : 在一个路由组件中滚动页面,切换到另一个组件中时,滚动条自动恢复到页面顶端的位置 下面的代...

  • vue 不默认滚动条位置

    scrollBehavior: () => ({ // 滚动条滚动的行为,不加这个默认就会记忆原来滚动条的位置 ...

  • vue全家桶(2.6)

    3.9.滚动行为 设置滚动行为的作用是导航到新路由时,让页面滚动到你想要的位置。 注意: 这个功能只在支持 his...

  • vue滚动行为

    scrollBehavior(只在支持history.pushState的浏览器可用) 使用场景:点击浏览器自带的...

  • 监听滚动条滚动到底部

    扩展UIScrollView 参考文章:Swift - RxSwift的使用详解68(监听滚动条滚动到底部的行为:...

  • vue的scrollBehavior滚动行为

    我们在使用vue-router做路由跳转时,如果想回退到上次页面时,并且向保存当时滚动到的位置,使用scrollB...

  • 滚动条恢复行为

    问题 Vue路由跳转,目标页面会继承起始页面的滚动条的位置。 history.scrollRestoration ...

  • Vue 路由 控制滚动行为

    作用:控制当前展示组件内容的具体位置 scrollBehavior(to,from,savedPosition){...

网友评论

      本文标题:滚动行为

      本文链接:https://www.haomeiwen.com/subject/tuzwuftx.html