W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
很多 Web 應(yīng)用程序都可能在某個時候有需要處理異步數(shù)據(jù)的需求。使用 Svelte 在標(biāo)簽中使用 await 處理 promise 數(shù)據(jù)亦是十分容易:
{#await promise}
<p>...waiting</p>
{:then number}
<p>The number is {number}</p>
{:catch error}
<p style="color: red">{error.message}</p>
{/await}
?
promise
?總是獲取最新的信息,這使得你無需關(guān)心 rece 狀態(tài)。
如果你的知道你的 promise 返回錯誤,則可以忽略 catch
塊。如果在請求完成之前不想程序執(zhí)行任何操作,也可以忽略第一個塊。
{#await promise then value}
<p>the value is {value}</p>
{/await}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: