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