vuepress-----25、右侧目录

# 25、vuepress 右侧目录

https://github.com/xuek9900/vuepress-plugin-right-anchor

vuepress-plugin-right-anchor

English |中文

在用 Vuepress 2.x 编写的文档页面右侧添加 锚点导航栏

# 版本

  • 2.x.x -> Vuepress 2.x -> npm next -> master 分支
  • 0.x.x -> Vuepress 1.x -> npm latest -> legacy 分支

# 特性

  • 简化左侧边栏结构的同时不丢失页面内标题导航的功能。
  • 点击锚点标签页面滚动过度。
  • 页面滚动时对应锚点标签跟随高亮。
  • 非全局组件,可在页面内自由使用。

# 安装

yarn add vuepress-plugin-right-anchor@next
# or
npm i vuepress-plugin-right-anchor@next -D

# 使用

.vuepress/config.js 添加如下配置。

module.exports = {
  // ...
  plugins: [
    // ...
    ['vuepress-plugin-right-anchor']
  ]
}

# 样式

.vuepress/styles/index.scss 添加样式变量。

.right-anchor {
  --rightAnchorTextColor: var(--c-text);
  --rightAnchorFontSize: 14px;
  /* Btn */
  --rightAnchorBtnTextColor: var(--rightAnchorTextColor);
  --rightAnchorBtnBgColor: var(--c-bg);
  /* Menu */
  --rightAnchorMenuTextColor: var(--rightAnchorTextColor);
  --rightAnchorMenuBgColor: var(--c-bg);
}

/* dark theme */
.dark .right-anchor {
  --rightAnchorTextColor: var(--c-text);
  --rightAnchorFontSize: 14px;
  /* Btn */
  --rightAnchorBtnTextColor: var(--rightAnchorTextColor);
  --rightAnchorBtnBgColor: var(--c-bg);
  /* Menu */
  --rightAnchorMenuTextColor: var(--rightAnchorTextColor);
  --rightAnchorMenuBgColor: var(--c-bg);
}

# 全局配置

.vuepress/config.js 添加如下配置。

module.exports = {
  // ...
  plugins: [
    // ...
    [
      'vuepress-plugin-right-anchor',
      {
        showDepth: 1,
        ignore: [
          '/',
          '/api/'
          // 更多...
        ],
        expand: {
          trigger: 'hover',
          clickModeDefaultOpen: true
        },
        customClass: 'your-customClass',
      }
    ]
  ]
}

# 参数说明

# showDepth

在右锚显示中将使用哪一级别的标题。 该值的指向含义与 themeconfig.sidebardepth (opens new window) 相同。

  • Type: null | number
  • Default: null

# ignore

不显示 right-anchor 的页面。

  • Type: array
  • Default: []

# expand

关于菜单的展开配置。

  • Type: object

    • trigger: string => 展开菜单的触发方式。 'hover' | 'click'
    • clickModeDefaultOpen: boolean => 点击模式下是否默认打开菜单?
  • Default:

    {
      trigger: 'hover',
      clickModeDefaultOpen: true
    }
    
    

# customClass

自定义的 right-anchor 类名。

  • Type: null | string
  • Default: null

# 页面单独配置

.md 中通过 vuepress 推荐的方式设置 front-matter

---
rightAnchor: 
  showDepth: 1
  expand:
    trigger: hover
    clickModeDefaultOpen: true
  customClass: your-customClass
---

image-20231214175111247

image-20231214175036131

本文转自 https://docs.xiaoshaozi.site/zs-tool-%E6%A1%86%E6%9E%B6/vuepress/

  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue3中实现跨组件锚点可以通过父子组件传参和路由监听来实现。 一种方法是通过父子组件传参实现。你可以将底部导航封装为一个组件,在子组件中定义一个自定义事件,例如`@anchorSkip`。在父组件中引入子组件,并监听`@anchorSkip`事件。当子组件触发该事件时,在父组件中使用`document.querySelector('#' + val).scrollIntoView()`来实现页面的锚点定位。具体的代码可以参考引用中的示例。 另一种方法是在父组件中监听路由或使用`updated`钩子。通过监听路由变化或在`updated`钩子中判断当前页面是否需要进行锚点定位。如果是从底部导航跳转过来的,可以使用`document.querySelector('#' + route.query.value).scrollIntoView()`来实现锚点定位。但需要注意的是,如果在同一个页面内多次点击同一个导航,是不会触发锚点定位的,因为路由(及传的参数)没有变化。此外,从其他不需要锚点定位的页面跳转过来后,页面可能会报`scrollIntoView()`方法错误。更多细节可以参考引用中的说明。 综上所述,你可以根据实际需求选择适合的方法来实现Vue3跨组件锚点。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [vue3跨页面锚点定位/页面跳转后使用锚点定位(vue2类似)](https://blog.csdn.net/weixin_54570626/article/details/129735561)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

悠闲的线程池

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值