Svelte组件在页面刷新时闪烁



无论我做什么,Child组件都会短暂出现,尽管showComponentfalse

为什么会发生这种情况?

我读到一个可能的原因可能是,在应用程序决定如何处理它之前,所有HTML都已呈现,但我不知道如何防止它

父组件

<script>
let entities;

async function getData(workspaceUid) {
entities = await fetchGet(`/api/workspaces/${workspaceUid}/entities`);
}

$: fetchEntities($workspaceUid);

$: showComponent = entities.length > 0
</script>

<Child bind:showComponent />

子组件

{#if showComponent}
content
{/if}

我设法阻止了它。

<script>
let entities;
let showComponent;

async function getData(workspaceUid) {
entities = await fetchGet(`/api/workspaces/${workspaceUid}/entities`);
showComponent = entities.length > 0
}

$: fetchEntities($workspaceUid);

</script>

<Child bind:showComponent />

最新更新