sveltejs-cn / svelte-cn

Svelte 中文文档
https://sveltejs-cn.github.io/svelte-cn/
16 stars 0 forks source link

Await blocks翻译校准 #32

Closed yuwanli closed 5 years ago

yuwanli commented 5 years ago

Await

{#await expression}...{:then name}...{:catch name}...{/await}
{#await expression}...{:then name}...{/await}
{#await expression then name}...{/await}

await 可以让你分支处理 Promise 的三种状态 pending, fulfilled, rejected

{#await promise}
    <!-- promise is pending -->
    <p>waiting for the promise to resolve...</p>
{:then value}
    <!-- promise was fulfilled -->
    <p>The value is {value}</p>
{:catch error}
    <!-- promise was rejected -->
    <p>Something went wrong: {error.message}</p>
{/await}

如果在 Promise reject时不需要渲染任何东西(或者不会出现错误),则可以省略catch块。

{#await promise}
    <!-- promise is pending -->
    <p>waiting for the promise to resolve...</p>
{:then value}
    <!-- promise was fulfilled -->
    <p>The value is {value}</p>
{/await}

如果你不关心pending状态,也可以省略初始化的状态。

{#await promise then value}
    <p>The value is {value}</p>
{/await}
yuwanli commented 5 years ago

@Copyes @tgxpuisb @dujuncheng @daixinye