RadioCell.vue 1.02 KB
<!-- components navbar-->
<template>
  <van-cell :title="title || data.name" class="radio" :class="clazz" :required="isRequire">
    <template>
      <van-radio-group v-model="comValue" @change="handleChange" direction="horizontal">
        <van-radio :name="item.value" v-for="item in data.value" :key="item.name">{{ item.name }}</van-radio>
      </van-radio-group>
    </template>
  </van-cell>
</template>

<script>
export default {
  name: 'RadioCell',
  props: ['title', 'data', 'value', 'clazz', 'isRequire'],
  computed: {
    comValue: {
      get() {
        if (this.value === null && this.isRequire) {
          this.$emit('update:value', this.data.value[0].value)
          return this.data.value[0].value
        }
        return this.value
      },
      set(val) {
        this.$emit('update:value', val)
      }
    }
  },
  data() {
    return {}
  },
  methods: {
    handleChange(value) {
      this.$emit('change', value)
    }
  }
}
</script>
<style lang="scss" scoped>
@include cellradio();
@include recell(0);
</style>