vue頁面跳轉頁面並且到對應錨點


查詢很多資料。發現寫法很復雜,如果要求不高,可以試試以下方法

 router-----------   /#/serve#serve5 

methods: {
    getLocal() {
      var hash = window.location.hash;
      var index = hash.lastIndexOf("#");
      var id = hash.substring(index + 1, hash.length + 1);
      var div = document.getElementById(id);
      if (index != -1) {
        div.scrollIntoView(true);
      }
    }
  },
  created() {
    this.$nextTick(() => {
      this.getLocal();
    });
  },
  mounted() {
    var hash = window.location.hash;
    var index = hash.lastIndexOf("#");
    if (index != -1) {
      this.$nextTick(() => {
        window.addEventListener("scroll", this.handleScroll);
      });
    }
  }
 
 
 
以上處理相對來說比較簡單
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM