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) } }
}