我在Svelte 3的任何地方都找不到此功能。我希望它是这样的。
瘦身
<Error>
<p>Can't connect to the server!</p>
</Error>`
Run Code Online (Sandbox Code Playgroud)
Error.svelte
<div>{props.children}</div>
我希望App.svelte显示 <div><p>Can't connect to the server!</p></div>
我只知道如何使用React的props.children
我希望这是完全客户端渲染..所以,我不想刷新页面只是为了重做承诺..
这是我制作的代码..
{#await myFetchMethod("/api/v1/me")}
<Loading />
{:then loggedIn}
{#if loggedIn}
<Link class="mb-0 h3" to="/profile">Profile</Link>
<Link class="mb-0 h3" to="/logout">Logout</Link>
{:else}
<Link class="mb-0 h3" to="/login">Login</Link>
<Link class="mb-0 h3" to="/register">Register</Link>
{/if}
{:catch error}
<p>Can't connect to the server!</p>
<button on:click={whatShouldIDoHere}>Refresh</button>
{/await}
Run Code Online (Sandbox Code Playgroud)
我希望刷新按钮只是重做myFetchMethod("/api/v1/me")
承诺并按预期获得结果。