enum-data.vue 1.3 KB
Newer Older
Y
yurj26 已提交
1
<script lang="uts">
雪洛's avatar
雪洛 已提交
2
  import { ItemType } from './enum-data'
3

D
DCloud_LXH 已提交
4
  export default {
5
    emits: ['change'],
D
DCloud_LXH 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
    props: {
      title: {
        type: String,
        default: ''
      },
      items: {
        type: Array as PropType<Array<ItemType>>,
        required: true
      }
    },
    data() {
      return {
        current: 0
      }
    },
    methods: {
      // @ts-ignore
      _change(e : RadioGroupChangeEvent) {
24
        const selected = this.items.find((item : ItemType) : boolean => {
25
          return item.value.toString() == e.detail.value
D
DCloud_LXH 已提交
26
        })
雪洛's avatar
雪洛 已提交
27
        if (selected != null) {
28
          this.$emit('change', selected.value)
D
DCloud_LXH 已提交
29 30 31 32 33 34 35 36
          uni.showToast({
            icon: 'none',
            title: '当前选中:' + selected.name,
          })
        }
      }
    }
  }
37 38 39
</script>

<template>
D
DCloud_LXH 已提交
40 41 42 43 44 45
  <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">
A
Anne_LXM 已提交
46
    <radio-group @change="_change">
D
DCloud_LXH 已提交
47
      <radio class="uni-list-cell uni-list-cell-pd radio" v-for="(item, index) in items" :key="item.name"
48
        :class="index < items.length - 1 ? 'uni-list-cell-line' : ''" :value="item.value">
D
DCloud_LXH 已提交
49 50 51 52
        {{ item.name }}
      </radio>
    </radio-group>
  </view>
53 54
</template>

D
DCloud_LXH 已提交
55
<style></style>