enum-data.vue 1.2 KB
Newer Older
Y
yurj26 已提交
1
<script lang="uts">
2 3 4 5 6 7 8 9 10
	export type ItemType = { value : number; name : string }

	export default {
		props: {
			title: {
				type: String,
				default: ''
			},
			items: {
fxy060608's avatar
fxy060608 已提交
11 12
				type: Array as PropType<Array<ItemType>>,
				required: true
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
			}
		},
		data() {
			return {
				current: 0
			}
		},
		methods: {
			// @ts-ignore
			_change(e : RadioGroupChangeEvent) {
				const selected = this.items.find((item) : boolean => {
					return item.name === e.detail.value as string
				})
				this.current = selected?.value as number
				this.$emit('change', this.current)
28
				uni.showToast({
29 30
					icon: 'none',
					title: '当前选中:' + selected?.name,
31
				})
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
			}
		}
	}
</script>

<template>
	<view class="uni-padding-wrap">
		<view class="uni-title uni-common-mt">
			<text class="uni-title-text"> {{title}} </text>
		</view>
	</view>
	<view class="uni-list uni-common-pl">
		<radio-group @change="_change" class="radio-group">
			<radio class="uni-list-cell uni-list-cell-pd radio" v-for="(item, index) in items" :key="item.name"
				:class="index < items.length - 1 ? 'uni-list-cell-line' : ''" :value="item.name" :checked="index === current">
				{{ item.name }}
			</radio>
		</radio-group>
	</view>
</template>

53
<style></style>