a***@163.com
a***@163.com
  • 发布:2024-10-29 18:22
  • 更新:2024-10-29 18:22
  • 阅读:55

我做一个动态的radio组件,无法读取到初始化的值

分类:HBuilderX

<template>
<view>
<form @submit.prevent="handleSubmit">
<view class="item">
<label>业态</label>
<radio-group v-model="formData[eField]">
<label class="radio-label" v-for="(option, index) in options" :key="index">
<radio :value="(index + 1).toString()">{{ option }}</radio>
</label>
</radio-group>
</view>
<button type="submit">提交</button>
</form>
<view>当前选择:{{ formData[eField] }}</view>
</view>
</template>

<script>
export default {
data() {
return {
fieldsToDisplay: [
{
"DP": 0,
"DataType": "int",
"FL": 4,
"cField": "业态",
"eField": "nlog01",
"fldType": "3,商场,客户,供货商",
"model": 3
}
],
formData: { "nlog01": 2 },
options: [],
eField: "nlog01", // 直接在这里定义
};
},
created() {
this.initializeOptions();
console.log('初始化的选项:', this.options);
console.log('初始化的表单数据:', this.formData);
},
methods: {
initializeOptions() {
const fieldInfo = this.fieldsToDisplay[0];
if (fieldInfo.fldType) {
this.options = fieldInfo.fldType.split(',').slice(1);
}
},
handleSubmit() {
console.log('提交的数据:', this.formData);
}
}
};
</script>

<style>
.item {
margin-bottom: 20px;
}
.radio-label {
display: block;
}
</style>

2024-10-29 18:22 负责人:无 分享
已邀请:

要回复问题请先登录注册