博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何安装svelte_解决Svelte模板中的承诺
阅读量:2502 次
发布时间:2019-05-11

本文共 1115 字,大约阅读时间需要 3 分钟。

如何安装svelte

Promises are an awesome tool we have at our disposal to work with asynchronous events in JavaScript.

Promise是一个很棒的工具,可用于处理JavaScript中的异步事件。

The relatively recent introduction of the await syntax in ES2017 made using promises even simpler.

ES2017中相对较新的await语法介绍使使用promise更加简单。

Svelte provides us the {#await} syntax in templates to directly work with promises at the template level.

Svelte在模板中为我们提供了{#await}语法,可直接在模板级别使用promise。

We can wait for promises to resolve, and define a different UI for the various states of a promise: unresolved, resolved and rejected.

我们可以等待承诺解决,并为承诺的各种状态定义不同的UI:未解决,已解决和已拒绝。

Here’s how it works. We define a promise, and using the {#await} block we wait for it to resolve.

运作方式如下。 我们定义一个承诺,并使用{#await}块等待它解决。

Once the promise resolves, the result is passed to the {:then} block:

承诺解决后,结果将传递到{:then}块:

{#await fetchImage}  

...waiting

{:then data} Dog image{/await}

You can detect a promise rejection by adding a {:catch} block:

您可以通过添加{:catch}块来检测承诺被拒绝:

{#await fetchImage}  

...waiting

{:then data} Dog image{:catch error}

An error occurred!

{/await}

Run the example:

运行示例: :

翻译自:

如何安装svelte

转载地址:http://rxqgb.baihongyu.com/

你可能感兴趣的文章
win64 Python下安装PIL出错解决2.7版本 (3.6版本可以使用)
查看>>
获取各种类型的节点
查看>>
表达式求值-201308081712.txt
查看>>
centos中安装tomcat6
查看>>
从Vue.js窥探前端行业
查看>>
学习进度
查看>>
poj3368 RMQ
查看>>
“此人不存在”
查看>>
github.com加速节点
查看>>
解密zend-PHP凤凰源码程序
查看>>
python3 序列分片记录
查看>>
Atitit.git的存储结构and 追踪
查看>>
atitit 读书与获取知识资料的attilax的总结.docx
查看>>
B站 React教程笔记day2(3)React-Redux
查看>>
找了一个api管理工具
查看>>
C++——string类和标准模板库
查看>>
zt C++ list 类学习笔记
查看>>
git常用命令
查看>>
探讨和比较Java和_NET的序列化_Serialization_框架
查看>>
1、jQuery概述
查看>>