vue框架怎样实现选择题的答题功能?
Admin 2021-09-03 群英技术资讯 2225 次浏览
这篇文章主要给大家分享怎样用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网页验证码插件代码实例,有正好需要的同学可以测试研究下具体使用效果
现在很多网站都有搜索的功能,而经常搜索访问的朋友应该会注意的,再次搜索的时候会有搜索历史的显示,那么这样效果是怎样做的呢?本文就给大家介绍一下利用jquery插件怎样做一个搜索历史的功能。
前几天在vue运行项目过程中报错了,所以下面这篇文章主要给大家介绍了关于Vue报错Syntax Error:TypeError: this.getOptions is not a function的解决方法,需要的朋友可以参考下
方法:1、利用getAttribute()方法获取指定class的属性值;2、利用if语句判断获取到的指定class属性值是否为空即可,语法为“if(获取到的指定class属性值=null){不存在代码;}else{存在代码;}”。
javascript伪数组是什么意思?很多新手可能对于伪数组和数组的区别不是很了解,这篇文章主就要介绍javascript伪数组和数组,感兴趣的朋友可以参考下,希望大家阅读完这篇文章能有所收获,接下来小编带着大家一起了解看看。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008