forEach如何终止循环

2023-05-13,,

try {

try {
this.list.forEach(item => {
.....
throw new Error('end')
})
} catch(err) {
console.log('err',err)
}
// 实例
confirm() {
try {
this.questions.surveyModuleContentDTOS.forEach((item, index) => {
if (item.moduleType === '02') {
console.log('子组件', this.$refs['module' + index][0].checkSelf())
const result = this.$refs['module' + index][0].checkSelf()
if (!result.flag) {
alertDialog({
title: '温馨提示',
message: `请完成 ${result.questionItem.surveyQuestionDetailDTO.subject}`
})
this.score = 0
throw new Error('end') // 终止循环
}
this.score += result.score
}
})
console.log('执行到这里,说明校验通过了发送请求', this.score)
alertDialog({
title: '提示',
message: `您的测评得分为 ${this.score}分`,
buttonCallback: () => {
console.log('传给后端的数据', this.questions)
}
})
} catch (err) {
console.log('err', err)
}
}

  

}

forEach如何终止循环的相关教程结束。

《forEach如何终止循环.doc》

下载本文的Word格式文档,以方便收藏与打印。