vue框架怎样实现选择题的答题功能?
Admin 2021-09-03 群英技术资讯 2395 次浏览
这篇文章主要给大家分享怎样用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进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
有时候我们只需要执行一次事件,那么在jquery中有什么方法能实现这个需求呢?文中主要介绍one()实现元素只执行一次事件的方法,下文有示例供大家参考,感兴趣的朋友可以了解看看。
小程序间的跳转怎样做?我们知道小程序之间是可以实现互相跳转的,这样好处就是现实流量的循环。那么接下来就给大家分享一下实现小程序间的跳转的两种方式,感兴趣的朋友可以了解看看。
这篇文章给大家分享的是有关js实现购物车功能模块的内容,小编觉得挺实用的,因此分享给大家做个参考,感兴趣的朋友接下来一起跟随小编看看吧。
这篇文章主要为大家详细介绍了Vue组件库ElementUI实现表格列表分页效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
前言在直播中,创建房间,获取房间,都需要服务器,因此需要搭建Web服务器Web服务器能处理HTTP请求的服务器都可以叫Web服务器Node.js介绍Node.js什么时候出现,2009年,Ryan Dahl(瑞恩·达尔)在GitHub上发布了最初版本的部分Node.
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
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核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008