如何将 <template> 标签呈现为实际的 DOM 元素?

How to render a <template> tag as an actual DOM element?

我目前正在编写一个使用 <template> tags for obtaining markup that it should render. To be compatible with reactive frameworks like Vue, it uses a MutationObserver 动态查找新元素的脚本。但是,<template> 标记在 Vue 中保留用于其自身用途。有没有办法告诉 Vue 像对待任何其他标签一样对待这样的标签并将其呈现在 DOM?

您可以在 Vue 中使用 is 指令根据 docs.

生成动态组件

如此有效,这会在 HTML DOM 中生成一个 <template> 标签。

<div is="template">
   <p>Some content</p>
</div>