vue项目中实现锚点跳转

vue实现a标签的锚点跳转功能

 <li @click="anchorJump">
            <span class="anchorEle">jump</span>
  </li>
 anchorJump() {
    const anchorEle = document.querySelector("#anchor");
    if (!!anchorEle ) {
      anchorEle .scrollIntoView(true);
    }
  }

document.querySelector("要返回地方的id").scrollIntoView(true);

    原文作者:MangoGoing
    原文地址: https://segmentfault.com/a/1190000018565969
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞