fetch('xxxurl.com').then(res=>{
if(res.status === 'ok') {
console.log('我应该如何跳出,不执行下一个then?');
} else {
return 'ok,可以继续';
}
}).then(res=>{
console.log(res);
});
我希望根据状态来判断是否要执行接下来的then,应该怎么做?
fetch('xxxurl.com').then(res=>{
if(res.status === 'ok') {
console.log('我应该如何跳出,不执行下一个then?');
} else {
return 'ok,可以继续';
}
}).then(res=>{
console.log(res);
});
我希望根据状态来判断是否要执行接下来的then,应该怎么做?
这样算不算一种方式:
fetch('1.png')
.then(function(){
console.log(arguments);
throw new Error('test');
})
.then(function(){
console.log('end')
})
.catch(function(exc){
console.log(exc);
});
13 回答13k 阅读
7 回答2.1k 阅读
5 回答1.4k 阅读
3 回答2.6k 阅读✓ 已解决
3 回答1.3k 阅读✓ 已解决
5 回答1.6k 阅读✓ 已解决
2 回答1.4k 阅读✓ 已解决
所以,你的代码应该这么写才对