You need to enable JavaScript to run this app. VuePress使用vue自定义容器展示文件夹结构渲染异常如何解决
优惠活动
大模型
产品
解决方案
定价
更多

VuePress使用vue自定义容器展示文件夹结构渲染异常如何解决

问题原因

你使用的::: vue标记是自定义容器语法,默认VuePress环境未内置该容器的解析规则,未被识别的容器标记会导致内部内容按普通行内文本渲染,最终出现排版混乱的问题。


解决方案

方案1:标准代码块实现(推荐,无需额外配置)

直接将整个目录结构用```text 代码块包裹,即可保留固定缩进和树状结构,无需安装额外插件:

.
├── docs
│   ├── .vuepress *(可选)*
│   │   ├── `components` *(可选)*
│   │   ├── `theme` *(可选)*
│   │   │   └── Layout.vue
│   │   ├── `public` *(可选)*
│   │   ├── `styles` *(可选)*
│   │   │   ├── index.styl
│   │   │   └── palette.styl
│   │   ├── `templates` *(可选,风险项)*
│   │   │   ├── dev.html
│   │   │   └── ssr.html
│   │   ├── `config.js` *(可选)*
│   │   └── `enhanceApp.js` *(可选)*
│   │ 
│   ├── README.md
│   ├── guide
│   │   └── README.md
│   └── config.md
│ 
└── package.json

注:普通代码块内的行内代码、斜体标记会被识别为普通文本,如果你需要保留这些格式效果,可以用第二种方案。

方案2:自定义容器实现带格式的渲染效果

如果你需要保留内容内的markdown格式,可以自行配置自定义容器规则:

  1. 安装对应版本的容器插件:
    • VuePress 1.x:
    npm install -D @vuepress/plugin-container@next
    
    • VuePress 2.x:
    npm install -D @vuepress/plugin-container
    
  2. 在.vuepress/config.js中添加插件配置:
module.exports = {
  plugins: [
    ['@vuepress/container', {
      type: 'vue',
      before: '<pre class="vue-tree-container"><code>',
      after: '</code></pre>',
    }]
  ]
}
  1. 可选:添加自定义样式优化展示效果,在.vuepress/styles/index.styl中加入:
.vue-tree-container
  padding 1rem 1.5rem
  border-radius 4px
  background-color #f6f8fa
  border-left 4px solid #3eaf7c
  font-family monospace

配置完成后你原来写的::: vue包裹的目录结构就可以正常渲染。


内容的提问来源于stack exchange,提问作者coure2011

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.08 11:51:01