用 element plus 写一个 switch 组件
时间: 2023-05-30 22:07:08 浏览: 59
<template>
<div>
<div v-for="option in options" :key="option.value">
<input
type="radio"
:id="option.label"
:value="option.value"
v-model="selected"
/>
<label :for="option.label">{{ option.label }}</label>
</div>
</div>
</template>
<script>
import { defineComponent } from 'vue';
export default defineComponent({
name: 'MySwitch',
props: {
options: {
type: Array,
required: true,
},
value: {
type: String,
required: true,
},
},
data() {
return {
selected: this.value,
};
},
watch: {
selected() {
this.$emit('update:value', this.selected);
},
},
});
</script>