考试功能
# 统一答题最后提交,
vue2实现
<template>
<div>
<div v-for='(i,index) in list' :key='index'>
<template v-if='index == activeIndex'>
<div>{{i.questionTitle}}</div>
<div>
<div v-for='(j,ji) in i.options' @click='handleSelect(index, ji)'>
{{j.optionTitle}}
</div>
</div>
</template>
</div>
<div>
<div v-if='activeIndex > 0' @click='activeIndex = activeIndex - 1'>上一题</div>
<div v-if='activeIndex < list.length - 1' @click='activeIndex = activeIndex + 1'>下一题</div>
</div>
</div>
</template>
<script>
export default {
data(){
return {
list: [
{
questionTitle: '单选',
questiontype: 'ss',
id: '1',
options:[
{optionTitle:'选项1',optionId:'1',isSelect:false},
{optionTitle:'选项2',optionId:'2',isSelect:false}
]
},
{
questionTitle: '多选',
questiontype: 'ms',
id: '2',
options:[
{optionTitle:'选项1',optionId:'3',isSelect:false},
{optionTitle:'选项2',optionId:'4',isSelect:false}
]
},
{
questionTitle: '判断',
questiontype: 'pd',
id: '3',
options:[
{optionTitle:'选项1',optionId:'5',isSelect:false},
{optionTitle:'选项2',optionId:'6',isSelect:false}
]
},
], // 题目列表
activeIndex:0, // 当前第几题
}
},
mounted(){
// 获取list,并将list每一项的option添加默认未选中 isSelect = false
},
methods:{
handleSelect(index,childIndex){
// 多选操作
if(this.list[index.questiontype] == 'ms'){
this.list[index.questiontype].options[childIndex] = !this.list[index.questiontype].options[childIndex]
}
// 单选 & 判断相似同一个处理方法
else{
// 全部设为不选
this.list[index.questiontype].options.forEach(i=>i.isSelect = false)
// 点击的设为选中
this.list[index.questiontype].options[childIndex].isSelect = true
}
},
// 提交事件
submit(){
// 处理数据格式,将选中的过滤提取选项id
// list: [{id:'1',userSelect:'1'},{id:'2',userSelect:'3,4'},{id:'3',userSelect:'6'}]
},
},
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
上次更新: 2023/07/20, 16:40:29