美文网首页
vue中页面跳转,显示在顶部

vue中页面跳转,显示在顶部

作者: 华华00526 | 来源:发表于2019-03-20 11:34 被阅读0次

页面之间跳转,打开新的一个页面显示在顶部

在main.js 中添加代码:

router.afterEach((to,from, next) => {

  window.scrollTo(0,0)

})

或者

在index.js里添加

exportdefaultnew Router({

  routes: [{...}],

  scrollBehavior(to, from,savedPosition) {

    return {

      x: 0,

      y: 0    }

  }

})

相关文章

网友评论

      本文标题:vue中页面跳转,显示在顶部

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