uniapp多个单选

文章描述:

  <template> <view> <view v-for=”(i […]

 

<template>
	<view>
		<view v-for="(itemx,i) in list" :key="i">
			{{itemx.question}}
			<view>
				<!--  -->
				<radio-group @change="radioChange($event,i)" style="display: flex;">
					<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in itemx.checkArr" :key="item.v" >
						<radio :value="item.v" :checked="item.v === itemx.answer" />{{item.t}}
					</label>
				</radio-group>
			</view>
		</view>
		
	</view>
</template>
 
<script>
export default{

	data(){
		return{
			Options:[{t: '是 Yes', v: 1}, {t: '否 No', v: 0}],
			questionsData:[],
			list: [
				{
					"id": 1,
					"question": "你来自中国",
					"en_question": "111",
					"question_score": 1,
					"type": "radio",
					"status": 1
				},
				{
					"id": 2,
					"question": "你是四川人",
					"en_question": "222",
					"question_score": 1,
					"type": "radio",
					"status": 1
				},
				{
					"id": 3,
					"question": "你是老乡",
					"en_question": "333",
					"question_score": 1,
					"type": "radio",
					"status": 1
				},
			]
		}
	},
	onLoad() {
		
	},
	onShow() {
		let eq = this.list
		
		eq.forEach((item,i)=>{
			item.answer = 1
			item.checkArr = this.Options
		})
		
		this.questionsData = eq
		
	},
	methods:{
		radioChange(e,i)
		{
			console.log(e.detail.value)
			console.log(i)
		},
	}
}
</script>
 
<style lang="scss">

</style>

 

 

发布时间:2023/12/12

发表评论