我有一个简单的 PrimaryButton.svelte 组件,仅包含“HTML”(没有脚本或样式标签),如下所示:
<button class="btn-primary btn accent--br">Primary button</button>
Run Code Online (Sandbox Code Playgroud)
然后我将该组件导入到 App.svelte 中,它在浏览器中呈现得很好,但我还想显示该组件的 HTML 代码。
App.svelte 看起来像这样:
<button class="btn-primary btn accent--br">Primary button</button>
Run Code Online (Sandbox Code Playgroud)
我尝试将其呈现为如下字符串:{PrimaryButton}而不是<PrimaryButton/>.
但浏览器显示了此字符串:
class PrimaryButton extends SvelteComponentDev { constructor(options) { super(options); init(this, options, instance$5, create_fragment$5, safe_not_equal, {}); dispatch_dev("SvelteRegisterComponent", { component: this, tagName: "PrimaryButton", options, id: create_fragment$5.name }); } }
Run Code Online (Sandbox Code Playgroud)
我有点希望它将组件的 HTML 显示为字符串,但我确实理解为什么这种情况没有发生。
如何在浏览器中将组件的输出 HTML 显示为字符串?你会怎么办?