JS跳出循环终止执行
作者:互联网
try{
let phones=[]
if(this.schoolInfo.phone!=''){
if(this.schoolInfo.phone.indexOf(',')>-1){
phones= this.schoolInfo.phone.split(',')
phones.some((item,index)=>{
if(!isMobile(item)){
this.$message({ message:'第'+(index+1)+"个手机号错误!", type: 'error' });
throw new Error("ending")
}
this.editLoading = false
})
}
}
}catch(e){
if(e.message == "ending"){
return
}else{
log(e.message);
}
}
用try{ }catch(e){ }来捕获异常,跳出执行
标签:catch,跳出,index,phones,schoolInfo,JS,phone,终止,message 来源: https://blog.csdn.net/guanrandang0061/article/details/113339315