一、前言                                                                                   

                               1、滚动事件

                               2、h5 history模式

二、主要内容                                                                            

1、   (1)使用前度路由,当切换到新路由时,想要页面滚动到顶部,或者是保持原先滚动的位置,就像重新加载页面那样。vue-router的滚动行为,它让你可以自定义路由切换的时候页面如何滚动

但是:这个功能history.pushState 的浏览器中可以使用

   (2)这个滚动行为只能在h5的history模式下使用,在使用滚动行为的时候必须要先将浏览器的hash模式,改成history模式

2、创建一个小例子模拟演示

  (1)目录结构如下

  Vue-router(基础)_滚动行为和history模式

  (2).vue文件如下.js文件如下

<template>
    <div>关于我页面</div>
</template>
<script type="text/javascript">
    export default{
        name:'About',
        data(){
            return {

            }
        }

    }
</script>

<style type="text/css" scoped></style>
About.vue

相关文章:

  • 2022-12-23
  • 2021-07-30
  • 2021-09-23
  • 2021-05-10
  • 2022-12-23
猜你喜欢
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2022-12-23
  • 2022-03-02
  • 2022-01-21
相关资源
相似解决方案