Markdown 中的 Vue 语法
博客文章使用 Markdown 来写文章,想在 Markdown 中使用 Vue 语法,关键代码:
html
<template>
<Essay />
</template>
<script setup>
import { defineAsyncComponent } from "vue";
import { parse } from "marked";
const Essay = defineAsyncComponent(() =>
fetch(`/docs/demo.md`)
.then((res) => res.text())
.then(parse)
.then((template) => ({ template }))
);
</script>
这种方式渲染 Markdown 时会导致 无法显示,使用 v-pre 也无法解决,所以还是改回 v-html,作此文以记录。