Using Vue in Markdown
Use Vue components and dynamic templating features directly inside Markdown files in VitePress.
In VitePress, each Markdown file is compiled into HTML and then processed as a Vue Single-File Component. This means you can use any Vue features inside the Markdown, including dynamic templating, using Vue components, or arbitrary in-page Vue component logic by adding a <script> tag.
It's worth noting that VitePress leverages Vue's compiler to automatically detect and optimize the purely static parts of the Markdown content. Static contents are optimized into single placeholder nodes and eliminated from the page's JavaScript payload for initial visits. They are also skipped during client-side hydration. In short, you only pay for the dynamic parts on any given page.
Templating
Section titled “Templating”Interpolation
Section titled “Interpolation”Each Markdown file is first compiled into HTML and then passed on as a Vue component to the Vite process pipeline. This means you can use Vue-style interpolation in text:
Input
{{ 1 + 1 }}Output
{{ 1 + 1 }}
Directives
Section titled “Directives”Directives also work (note that by design, raw HTML is also valid in Markdown):
Input
<span v-for="i in 3">{{ i }}</span>Output
{{ i }}
<script> and <style>
Section titled “<script> and <style>”Root-level <script> and <style> tags in Markdown files work just like they do in Vue SFCs, including <script setup>, <style module>, etc. The main difference here is that there is no <template> tag: all other root-level content is Markdown. Also note that all tags should be placed after the frontmatter:
---
hello: world
---
<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>
## Markdown Content
The count is: {{ count }}
<button :class="$style.button" @click="count++">Increment</button>
<style module>
.button {
color: red;
font-weight: bold;
}
</style>:::callout{intent="warning" title="Avoid