首页 >社区问答列表 >fetch如何中断then?

fetch如何中断then?

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

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

  • 三叔
  • 三叔    2016-10-28 15:07:171楼

    这样算不算一种方式:

        fetch('1.png')
            .then(function(){
                console.log(arguments);
                throw new Error('test');
            })
            .then(function(){
                console.log('end')
            })
            .catch(function(exc){
                console.log(exc);
            });


    +0添加回复

  • 回复