vue框架怎样实现选择题的答题功能?
Admin 2021-09-03 群英技术资讯 2312 次浏览
这篇文章主要给大家分享怎样用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进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章我们主要了解关于vue中router传参方式,本文有示例代码供大家参考,感兴趣的朋友可以了解看看,另外本文还分享了刷新页面数据丢失的解决方法,接下来我们一起了解看看吧。
监听属性可以针对某个属性进行监听,当监听的属性的值发生了变化,则会执行相应的函数,下面这篇文章主要给大家介绍了关于Vue监听属性的相关资料,需要的朋友可以参考下
这篇文章主要为大家介绍了Electron调用外接摄像头并拍照上传实例实现详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
这篇文章主要为大家介绍了vue parseHTML函数源码解析 AST预备知识示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
怎样用vue实现点赞动画效果?现在很多网站平台都有点赞功能,这篇文章就给大家分享怎样用vue实现一个好看的点赞动画,当点赞时,同时点亮爱心和增加点赞数,效果如下,感兴趣的朋友就继续往下看吧。
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008