【发布时间】:2021-03-07 11:45:49
【问题描述】:
我正在尝试将 Svelte 与 gridstack 一起使用。但是当我在 js 中添加我的 Svelte 组件时,它并没有正确显示。这会添加一个按钮,但样式不起作用,并且输出不会打印到日志中。
<script>
import { onMount } from "svelte";
import Button from "./Button.svelte";
import GridStack from "gridstack/dist/gridstack.all.js";
import "gridstack/dist/gridstack.min.css";
onMount(() => {
var grid = GridStack.init();
grid.addWidget({ width: 2, content: "<p>Hello</p>" });
grid.addWidget({ width: 2, content: "<Button />" });
});
</script>
<style>
</style>
<div class='grid-stack'></div>
完整示例:https://codesandbox.io/s/gallant-roentgen-jmnis?file=/App.svelte
【问题讨论】:
-
您没有传递
<Button>组件,而是传递了"<Button/>"字符串,该字符串被解析为HTML。