一个简单的radiogroup绑定

一个简单的radiogroup绑定demo

<template>
	<view>
		<view class="uni-list">
			<radio-group @change="radioChange">
				<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value">
					<view>
						<radio :value="item.value" :checked="index === current" />
					</view>
					<view>{{item.name}}</view>
				</label>
			</radio-group>
		</view>
		<!-- 输出点击的哪一项  -->
		<view>选择了:{{selectItem}},多少钱{{howmuch}}</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 输出列表
				items: [{
						value: 'pork',
						name: '猪肉',
						money:"30.00"
					},
					{
						value: 'beef',
						name: '牛肉',
						money:"45.00"
					},
					{
						value: 'fish',
						name: '鱼',
						money:"14.00"
					},
					{
						value: 'break',
						name: '面包',
						money:"2.50"
					},
					{
						value: 'guodong',
						name: '果冻',
						money:"24.00"
					},
					{
						value: 'tomato',
						name: '西红柿',
						money:"8.00"
					},
				],
				// 点击了第几个
				current: [],
				// 已经选择
				selectItem:"",
				howmuch:""
			}
		},
		methods: {
			radioChange(evt) {
				for (let i = 0; i < this.items.length; i++) {
					// evt.detail.value  点击
					if (this.items[i].value === evt.detail.value) {
						// 第几个
						this.current = i;
						break;
					}
				}
				// 选了什么显示
				this.selectItem=this.items[this.current].name
				// 多少钱显示
				this.howmuch=this.items[this.current].money
				// 更新
				this.$forceUpdate();
			}
		}
	}
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值