html
<el-dialog v-model="dialog.visible" :title="dialog.title" destroy-on-close append-to-body width="600px">
<el-form ref="categoryFormRef" :model="form" :rules="rules" label-width="80px">
<el-row>
<el-col :span="12">
<el-form-item label="分类名称" prop="categoryName">
<el-input v-model="form.categoryName" placeholder="请输入分类名称" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="关联单位" prop="unitId">
<el-select v-model="form.unitId" filterable clearable placeholder="请选择">
<el-option
v-for="item in unitOptions"
:key="item.unitId"
:label="item.unitName"
:value="item.unitId"
></el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</template>
</el-dialog>
javascript
const unitOptions = ref<AdspunitVO[]>([]);
const listAdspunitAllLocal = async () => {
if(!unitOptions.value.length){
const resUnit = await listAdspunitAll();
unitOptions.value = resUnit.data;
}
}
// 单位生成 ID-Name 映射字典
const idToNameUnitMap = computed(() => {
return unitOptions.value.reduce((map, item) => {
map[item.unitId] = item.unitName;
return map;
}, {});
});
// 格式化函数
const idUnitFormatter = (row, column, cellValue) => {
if(!cellValue){
return;
}
return idToNameUnitMap.value[cellValue] || '';
};
onMounted(() => {
getList();
listAdspunitAllLocal();
});
比如以上关联单位字段来源于其他表