解决element中的el-anchor链接被作为路由跳转导致页面404

问题:

在使用elementPlus时,el-anchor-link中的href被识别为路由进行跳转,导致不能正常跳转到锚点,且页面显示404。

解决:自定义方法解决

<!--添加handleAnchorClick方法-->
 <el-anchor type="underline" :offset="70" @click="handleAnchorClick"></el-anchor>
const handleAnchorClick = (e, link) => {
// 取消浏览器默认行为
 e.preventDefault();
 // 取选择器,通过dom查找元素
 const el = document.getElementById(link.split("#")[1]);
 // 跳转
 if (el) {
   el.scrollIntoView({ behavior: "smooth" });
 }
};

更多推荐