<template>
<view class="questionnaire">
<view class="section">
<view class="title">
一、财务状况
</view>
<view class="block" v-for="(item,index) in questionList" :key="index">
<view class="question">
{{item.question}}
</view>
<view class="selection" v-for="(answer,index1) in item.answer" :key="index1">
<van-radio-group value="radio" @change="onChange(answer.mask)">
<van-radio custom-class="radio" checked-color="rgb(213,0,15)">{{answer.content}}</van-radio>
</van-radio-group>
</view>
</view>
</view>
</view>
</template>
<script>
export default{
data(){
return{
questionList:[
{
qId:1,
question:'1.您的年龄是?',
answer:[
{content:"18-30岁",mask:'-2'},
{content:"31-50岁",mask:'0'},
{content:"51-60岁",mask:'-4'},
{content:"高于60岁",mask:'-10'}
],
},
],
totalMask:0,
radio:''
}
},
methods:{
// onChange(e){
// console.log('e:',e)
// }
onChange(mask) {
console.log('mask:',mask)
this.totalMask+=Number(mask),
console.log('this.totalMask:',this.totalMask)
console.log('this.totalMask+1:',this.totalMask+1)
},
}
}
</script>
<style>
.questionnaire{
margin: 5px auto;
width: 90%;
}
.title{
margin: 5px 0px;
}
.block{
margin: 5px;
}
.question{
margin:5px 0px;
}
.radio{
margin:5px 0px;
}
</style>
现在变成了如下状况:单选题变成了多选题
请问有何高见,请赐教,不胜感激。
change
事件,要么用事件冒泡在上层侦听,要么直接绑定数据也行