组件
<template>
<div>
<el-button-group>
<el-button
style='margin-right: 15px'
v-for="(btn, index) in buttons"
:key="index"
:type="value === btn.value ? 'primary' : ''"
@click="$emit('input', btn.value)"
>
{{ btn.label }}
</el-button>
</el-button-group>
</div>
</template>
<script>
export default {
name: 'MyRadio',
props: {
value: Boolean,
buttons: {
type: Array,
default: () => [
{ label: '是', value: true },
{ label: '否', value: false }
]
}
},
data() {
return {
}
}
}
</script>
页面使用
<template>
<div>
<h3>您是否喜欢这个单选组件?</h3>
<my-radio v-model="likesIt" />
</div>
</template>
<script>
import MyRadio from './MyRadio.vue'
export default {
components: { MyRadio },
data() {
return {
likesIt: null
}
}
}
</script>