fetch中then()的操作
来源:4-10 异步Action(1)

慕容4009360
2020-03-20
老师:您好!请问这里的 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
你好,两种写法基本等价,都可以捕获前面程序抛出的异常。
00
相似问题