如何实现锚点跳转


  • 路由模式: 设置为 hash 模式
  • 路由跳转前:URL 的 hash 值为目标页面锚点的名称
  • 路由跳转后
    • 生命周期: 触发目标组件 mounted 生命周期回调
    • 获取 hash: 获取 hash 值并找到对应 DOM 元素
    • 滚动定位: 使用 scrollIntoView 方法滚动到 DOM 元素所在位置