javascript - 使用导入的原始 html 时 v-html 无法按预期工作
问题描述
我在 Vue2 中有一个带有 vue-cli/3 的组件,它有很多原始 HTML。与其把我的组件弄得乱七八糟,我想我会把它抽象为一个单独的模块并导入它。但是,在渲染时出现以下错误:
Vue warn]: Invalid component name: "
<img src="../assets/img/elizabeth_i_article.jpg" alt="Elizabeth the I">
<p>Elizabeth I, bynames <strong>the Virgin Queen</strong> and <strong>Good Queen Bess</strong>, (born September blah blah lot more ...
我在 vue 工具中看到 App 下有一个以 html 为名称的组件条目,并且我的值为 elizabethTheI :“html here ....”。第一行中的图像也不会渲染。但所有其他 HTML 呈现正常。
我的设置是
elizabeth_I.js:
const elizabethTheI = `
<img src="../assets/img/elizabeth_i_article.jpg" alt="Elizabeth the I">
<p>Elizabeth
... more html
`
export default elizabethTheI;
Elizabeth_I.vue:
<template>
<div class="container">
<h1>Elizabeth the I</h1>
<div v-html="elizabethTheI"></div>
</div>
</template>
<script>
import elizabethTheI from "./assets/elizabeth_I";
export default {
data() {
return {
elizabethTheI: elizabethTheI
};
}
};
</script>
我已经阅读了文档和几个教程,我认为我正确使用了 v-html 指令。任何关于我为什么会出现错误和图像不渲染的见解将不胜感激。
解决方案
推荐阅读
- typescript - 通用返回 T 的打字稿
- python - 如何使用 Tesseract OCR 从视频帧中提取数字?
- postgresql-9.5 - 错误:“SELECT”第 14 行或附近的语法错误:v_result := SELECT * FROM iis_e_ack_pkg.is_e_ack_confirm
- typescript - 在 create-react-app 中添加自定义反应脚本的标准方法
- python - 使用 Python 和 REST api 从 Sharepoint 中提取
- linux - 如何找到应该发送 AT 命令的端口(/dev/smdX)?
- javascript - JS:如何过滤一个对象数组,向第一个对象添加一个带有其余过滤元素值的键?
- google-cloud-networking - 使用 VPC 对等访问 Memorystore (Redis)
- android - 为什么 dwc3 usb 控制器没有报告 xfercomplete 事件?或者小工具驱动程序错过了那个事件?
- python - 从python中的巨大列表中获取前N个元素的最佳和最快方法