<template>
<el-form-item label="学生性别" prop="">
<el-radio-group v-model="sex" @change="onSexChange">
<el-radio :label="item.label" :key="item.id" v-for="item in sexOptions">
{{item.label}}
</el-radio>
</el-radio-group>
</el-form-item>
</template>
<script>
import { ref, toRefs } from 'vue';
export default {
setup() {
const state = reactive({
sex:'女生', //默认选中,设置为v-model的值
sexOptions: [
{
label: '男生',
id: 1,
},
{
label: '女生',
id: 2,
},
],
})
const onSexChange = (val) => {
console.log(val)
state.sex= val
}
return {
...toRefs(state),
onSexChange
};
},
};
</script>
element-plus:遍历el-radio及选中默认
于 2022-03-09 14:43:01 首次发布