我得到一个包含 60 个问题的 JSON,每 10 个问题中有 10 个问题显示一次。但在继续下 10 个问题之前,我需要检查是否所有问题都已得到回答。我的组件:<div class="test-questions comp" id="scrollb"> <div class="question" v-for="(q, index) in currentPageItems" :key="q.id"> <div class="statement"> {{q.id}}. {{q.text}} </div> <div class="options yes-no"> <div :class="{'active':relato.quest['q'+q.id] === 1}" class="caption option yes" @click="handleYes('q'+q.id, q.ck)">Sim</div> <div :class="{'active':relato.quest['q'+q.id] === 0}" class="caption option no" @click="handleNo('q'+q.id, q.ck)">Não</div> </div> </div> </div> <div class="action-row"> <button v-if="pageNumber <= 4" class="btn btn-green" @click="next()"><span>Próximo</span></button> <button v-if="pageNumber == 5" class="btn btn-green" @click="salvarRelato()"><span>Publicar</span></button> </div>解决这个问题的建议是什么?
1 回答
DIEA
TA贡献1820条经验 获得超2个赞
在next方法中检查每个qi( 0<i=<60) 的值是否等于1或0直到当前页面:
next(){
let valid=Object.values(this.relato.quest).slice(0,(pageNumber+1)*perpage).every(q=>q==0 || q==1)
if(valid){
this.pageNumber++;
document.getElementById("scrollb").scrollIntoView({behavior: "smooth"});
}
},
添加回答
举报
0/150
提交
取消