天天看點

vue路由跳轉 2021-03-13

路由跳轉後,傳回原界面,怎麼保持原頁面的滾動位置:

//to去哪兒

//from 從哪裡來的

// savedPosition 來的界面是否有滾動記錄

scrollBehavior (to, from, savedPosition) {
      if (savedPosition) {
        return savedPosition //傳回原頁面的滾動位置
      } else {
        return { x: 0, y: 0 } //如果沒有滾動,頁面回到頂部位置。
      }
    }
      
vue路由跳轉 2021-03-13