猿问

fetch如何中断then?

fetch('xxxurl.com').then(res=>{  if(res.status === 'ok') {    console.log('我应该如何跳出,不执行下一个then?');
  } else {    return 'ok,可以继续';
  }
}).then(res=>{    console.log(res);
});

我希望根据状态来判断是否要执行接下来的then,应该怎么做?


浮云间
浏览 902回答 1
1回答

湖上湖

这样算不算一种方式:    fetch('1.png')         .then(function(){            console.log(arguments);            throw new Error('test');         })         .then(function(){            console.log('end')         })         .catch(function(exc){            console.log(exc);         });
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答