HLJ 发布于
2019-01-18 16:03:19

vue radio组件封装调用

vue radio组件封装调用

父组件引用代码
<Radio :total="inputModeList2" :id="'c'" :random="Math.random()" 
:checked="attributeForm.showType" :disabled="attributeForm.id" @text="radioFn3"></Radio>
子组件代码
<template>
  <div>
    <template v-if="type==1">
      <!-- ['甲级','乙级','丙级'] -->
      <template v-for="(item,index) in total">
          <input type='radio' :disabled="disabled!=null"  
          v-model="val" :value="item" :id="id+index" :name="'radio'+id">
          <span v-html="item"></span>
      </template>
    </template>

    <template v-if="type==2">
      <template v-for="(item,index) in total">
          <input type='radio' :disabled="disabled!=null"  
          v-model="val" :value="item" :id="id+index" :name="'radio'+id">
          <span v-html="item"></span>
      </template>
    </template>
  </div>
</template>

<script>
    export default {
       //列表、id、、随机数、默认值、disabled状态,类型(1、对象数组;2简单数组)
      props: ["total","id","random","checked","disabled",'type'], 
        data() {
            return {
               val:this.checked,
            }
      },
      watch: {
        random(){
          this.val=this.checked;
        },
        val(newval,oldval) {
          this.test();
        },
      },
      methods:{
        test(){
          this.$emit('text',this.val);
        },
      }
    }
</script>

当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2019-01-18/337.html
最后生成于 2024-05-23 22:50:18
此内容有帮助 ?
0