javascript - 在运行时生成的 Vue 组件中添加或注入 HTML 或组件
问题描述
我有一个 Vue 应用程序,我在其中获取一堆 markdown 文件并将它们制作成动态生成的组件,其中的链接由 Vue Router 处理。我正在使用这个Vue 降价加载器加载我的降价。
主路由文件如下所示:
import RamblePosts from "@/assets/rambles/rambles.json"; // Simple JSON that contains the name of the markdown documents
...RamblePosts.map(entry => ({
path: `/${entry}`,
name: entry,
component: () => import(`@/assets/rambles/${entry}.md`)
}))
];
如您所见,我正在根据该目录中的降价文件生成组件。
示例用法是:
<template>
<div class="wrapper-div rambling-wrapper">
<div class="ramble-cards-wrapper">
<RambleCard
v-for="route in rambleList"
:key="route.title"
:title="route.title"
:subtitle="route.subtitle"
:ramble-url="route.url"
/>
</div>
</div>
</template>
<script>
import RambleCard from "@/components/RambleCard";
import rambleList from "@/assets/rambles/rambleList.json";
export default {
components: {
RambleCard
},
data() {
return {
rambleList
};
}
};
</script>
这是一个简单的卡片元素,仅显示 markdown 条目的名称、副标题和 vue-router 链接。单击链接将带您到相关文章,因此类似于url.com/foo
有没有办法让我以某种方式编辑或操作这些 Markdown 组件,并为它们添加一个 Vue 组件,甚至只是纯 HTML?由于它们是动态生成的,我不知道如何处理这种情况,因为我不能只是在这些文章组件中间的某个地方插入一个组件。
解决方案
推荐阅读
- windows - 如何在 Windows 上模拟 Com 端口并提供 VendorId 和 ProductId
- python - 熊猫数据框更新 - 更新期间完成的所有更改的日志
- javascript - useEffect 导致无限循环,但我找不到原因。另外我可以在代码中改进什么
- unicode - UAX#15 第 9 节中的 Unicode NFC 快速检查和补充字符示例
- linkedin-api - 将 LinkedIn 与 UKG 集成(HRIS 系统)
- flutter - 按下异步按钮内的 Flutter Navigator 页面更改
- ruby-on-rails - 为什么 Devise 允许我在不提供密码确认的情况下创建用户?
- java - 通过自定义 KeyCloak Config Resolver 获取 SecurityContextHolder.getContext().getAuthentication()
- java - 我的 TestNG 断言失败。有人可以在这里帮忙吗?我在这里做错了什么
- javascript - 仅插入具有值的变量,而不是未定义的 node.js