vue框架怎样实现选择题的答题功能?
Admin 2021-09-03 群英技术资讯 2127 次浏览
这篇文章主要给大家分享怎样用vue框架来实现选择题的答题功能,也就是选对选项跳下一题,选错则提示重新答题,下文有具体的代码,感兴趣的朋友可以参考,下面我们一起来了解一下吧。
1、请求答题接口
2、判断用户是否答对,答对的话跳到下一题,答错的话弹窗告诉用户有错题,请重新答题
<div class="active_title"> <span>{{ orderTitle }}</span> </div> <p v-show="toanswer" ref="question">{{ title }}</p> <div class="answer-btns" @click="answerClick($event)"> <span class="answer-btn" :class="`${isRight && item.result == 1?'right':''}`"
v-for="item in answer" :data-result='item.result'>{{ item.name }}
<i class="iconfont icon-wrong"></i><i v-show="isRight && item.result == 1" class="iconfont icon-right"></i> </span> </div>
getAllData() { this.$axios.get(答题接口).then((res)=>{ if(parseInt(res.data.errCode)>=0){ this.allData=res.data.data if(this.allData.question.length > 0) { this.toanswer = true } this.title = this.allData.question[0].title//第几题 this.answer = this.allData.question[0].answner//第几题问题 }else{ this.toast = this.$createToast({ txt: res.data.message, type: 'txt' }) this.toast.show() } }).catch((err)=>{ console.log(err) }) }, answerClick(e) { const tar = e.target, className = e.target.className if(className == "answer-btn") { this.mask = true const result = tar.dataset.result if(result == 1){ // console.log('选对',result); this.isRight = true $(tar).addClass('right') } else { // console.log('选错',result); this.isRight = true this.isWrong = true $(tar).addClass('wrong') setTimeout(() => { this.maskTips = true }, 1200); } setTimeout( () => { this.clickNum ++ if(this.clickNum > 2) { this.clickNum = 2 if(this.isWrong) { console.log('答错'); this.mask = false this.maskTips = true return false } else { console.log('答对了'); } } $('.answer-btn').removeClass('wrong') this.orderTitle = this.orderTitles[this.clickNum] this.isRight = this.mask = false this.title = this.allData.question[this.clickNum].title this.answer = this.allData.question[this.clickNum].answner },1200) } },
以上就是vue实现选择题答题功能的介绍,有需要的朋友可以参考上述代码,希望对大家学习有帮助,想要了解更多请搜索群英网络以前的文章或继续浏览其他相关的文章。
文本转载自脚本之家
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
今天给大家分享一个比较有趣的实例,相信很多朋友都有抢过微信红包吧,有的人红包抢到的金额的多,有的人抢到的少,那么大家是否有好奇这是怎样实现的,下面小编就给大家介绍一下用JavaScript实现指定红包金额的算法,感兴趣的朋友就继续往下看吧。
如果调用者在函数返回时无法获得预期的结果,但在未来需要通过一定的手段获得,那么函数是异步的。如果函数异步,调用后立即返回,但不会立即返回预期结果。
这篇文章主要介绍了Vue.js中NaiveUI组件文字渐变的实现,文章围绕主题展开详细的内容介绍,具有一定的参考价值,需要的小伙伴可以参考一下
这篇文章主要介绍JS数组去重,关于去重实际应用中,最常用的方法就是使用Set,也可以使用第三方库lodash来处理,下面一起来看看文章是怎么介绍JS数组去重的
这篇文章主要为大家介绍了网络请求方案原生网络请求和js网络请求库的过程示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008