【问题标题】:On route change view scroll to top in the new page in vue js在vue js的新页面中,路由更改视图滚动到顶部
【发布时间】:2020-08-06 18:21:27
【问题描述】:

我已经在路由器链接上尝试过 this.$router.replace(...) 但似乎不起作用,是否有任何默认的 vue 方法可以在不使用任何第三方库的情况下做同样的事情?

【问题讨论】:

    标签: javascript vue.js scroll


    【解决方案1】:

    在创建路由实例时,您可以提供scrollBehavior函数,帮助您在导航到新路由时滚动到顶部:

    const router = new VueRouter({
      routes: [...],
      scrollBehavior (to, from, savedPosition) {
          // return desired position
      }
    })
    

    更多详情可以关注https://router.vuejs.org/guide/advanced/scroll-behavior.html#async-scrolling

    【讨论】:

      猜你喜欢
      • 2021-12-22
      • 2017-02-17
      • 2014-01-30
      • 1970-01-01
      • 2019-05-10
      • 2019-10-24
      • 2020-07-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多