当前位置: 代码迷 >> 综合 >> vue 进入页面无点击自动定位到某一位置 锚点
  详细解决方案

vue 进入页面无点击自动定位到某一位置 锚点

热度:31   发布时间:2024-01-29 00:21:39.0

头部

 div加   @click="returnTop()"

 

methods里 

 returnTop() {

      document.querySelector("#headers").scrollIntoView(true); //跳转到顶部

      window.scrollTo(0, 0);

    },

 

// 刷新后也不影响 在mounted里加

 mounted() {

    console.log(this.$route.path);

    //获取地址栏中的路由,设置elementui中的导航栏选中状态

    this.activeIndex = this.$route.path;

  },

  相关解决方案