vue.js - 在 vuepress 中,如何将一些 md 内容动态呈现为客户主题(vue 模板)
问题描述
在主题的一个 .vue 文件(组件)中,我只想将如下所示的一些 md 内容动态呈现到 .vue 模板中
md内容:
::: slot aaa
# Here is slot aaa
:::
- A Paragraph
- Another Paragraph
::: slot bbb
Here is slot bbb
:::
而vue主题模板是这样的:
<template>
<div class="theme-container">
<Content slot-key="aaa" />
<br/>=============
<Content />
<br/>=============
<Content slot-key="bbb" />
<br />
</div>
</template>
而md内容我可以从一些后端api中获取,我想在页面中动态渲染,怎么办。
非常感谢。
解决方案
如果你想在 Vue 组件中渲染 markdown,你应该写一个 vuepress 插件。
我使用https://github.com/superbiger/vuepress-plugin-tabs源作为参考。你需要:
- 在 markdown-it-container 插件中定义自定义 md 容器,它应该解析打开和关闭容器标签
- 在 client.js 中定义你的 Vue 组件
- 为你的插件定义 index.js,它应该导出 enhanceAppFiles 和 chainMarkdown
- 在 .vuepress/config.js 中添加这个插件。
推荐阅读
- python-3.x - python中单词的动名词形式
- r - 在 R 中转换数据框
- scala - 使用 sbt 构建的应用程序运行时出现 NoClassDefFoundError
- html - 如何删除文件中的这一行?
- javascript - 为什么我的数组更新延迟,看起来像代码异步,但它是同步的。React 的简单示例 - JS
- python - push_san() 缺少 1 个必需的位置参数:“san”
- sql - SQL Sum count 2 列或更多列
- graphql - Lighthouse GraphQL - 如何将数组作为变量传递?
- java - App点击天气活动的搜索按钮,报告一直停止
- gradle - 在 missingProperty 之前调用类加载器