【发布时间】:2021-10-08 10:24:16
【问题描述】:
我想在我的 Vue.js 3 setup() 函数的变量中包含一些 HTML,以便稍后在模板中使用。
当我尝试以下操作时,我收到 "VueCompilerError: Invalid end tag." 错误,因为 Vue 似乎认为它是组件代码的一部分(当然不是)。
<script>
imports...
setup() {
const a = a;
const b = b;
const MyHTML = '<script></script>' // Vue thinks the </script> tag is part of the code
}
</script> // This gets thrown an error of VueCompilerError: Invalid end tag.
我怎样才能将 HTML 作为字符串存储在变量中而不被 Vue 解释?
【问题讨论】:
-
您能否发布一个可重现的示例,以便人们可以在干净的环境中验证这不起作用?
-
你可以用反斜杠
const MyHTML = '\<script\>\<\/script\>'
标签: javascript vue.js vuejs3