fetch中then()的操作

来源:4-10 异步Action(1)

慕容4009360

2020-03-20

http://img.mukewang.com/szimg/5e74b1ed091c224810540777.jpg

老师:您好!请问这里的 then()可以同时写response=>{},error=>{}

而不是

fetch('https://example.com/posts', {
 method: 'POST',
 body: formData}).then(response => response.json()).then(response => console.log('Success:', JSON.stringify(response))).catch(error => console.error('Error:', error));

为什么?谢谢

写回答

1回答

艾特老干部

2020-03-30

你好,两种写法基本等价,都可以捕获前面程序抛出的异常。

0
0

React16+Redux实战企业级大众点评Web App

从架构设计到部署上线,带你学习React技术栈与核心思想

1071 学习 · 306 问题

查看课程