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>