Refresh the page in vue to jump to the specified page and back to the top (browsing history is not affected by the last scrolling distance)

Problem Description:

  1. Realize page refresh and jump to the home page in vue
  2. Refresh back to top
  3. Refreshing the jump page in the project is affected by the scrolling distance of the previous page browsing

Solution:

  • In app.vue
  mounted() {
    
    
    // 刷新后跳转到首页面
    this.$router.push("/");
    //刷新后回到顶部
    window.addEventListener("beforeunload", (e) => {
    
    
      window.scroll(0, 0);
    });
  },

Guess you like

Origin blog.csdn.net/weixin_44693565/article/details/113879164
Recommended