Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请求完后端数据返回后无法回填form-edit.vue中的数据 #382

Open
qianying1 opened this issue Apr 22, 2024 · 0 comments
Open

Comments

@qianying1
Copy link

仿造user.vue代码改写增加的一个文件如下:




<script setup lang="ts"> import { ref, onMounted } from 'vue'; import Vue from 'vue'; import { ElMessage } from 'element-plus'; import { MemberGrade } from '@/types/member'; import { fetchMemberGradeData, updateMemberGradeData } from '@/api'; import TableEdit from '@/components/table-edit.vue'; import { FormOption } from '@/types/form-option'; const form = ref({ mbrgId: 0, name: 'huhhjh', downloadPerdayLimit: 0, downloadTotalLimit: 0, expireTm: 0, isDelete: '', owner: '', price: 0, createTm: new Date(), updateTm: new Date() }); const options = ref({ labelWidth: '180px', span: 12, list: [ { type: 'input', label: '会员等级名称', prop: 'name', required: true }, { type: 'number', label: '价格', prop: 'price', required: true }, { type: 'number', label: '每日下载次数限制', prop: 'downloadPerdayLimit', required: true }, { type: 'number', label: '总下载次数限制', prop: 'downloadTotalLimit', required: true }, { type: 'input', label: '时间天数(-1代表无效期)', prop: 'expireTm', required: true }, { type: 'hidden', label: '会员等级ID', prop: 'mbrgId', required: false, disabled: true, hidden: true }, ] }); const getData = async () => { try { const res = await fetchMemberGradeData({ "owner": "first" }); if (res.data.success) { const data = res.data.data; // 更新表单数据 form.value = data; console.log('表单数据:', form.value); // 打印表单数据 ElMessage.success(form.value.name); } else { ElMessage.error(res.data.msg); } } catch (error) { console.error('Error fetching data:', error); } }; const updateData = async () => { try { console.log("update data!"); console.log(form.value); const res = await updateMemberGradeData(form.value); if (res.data.success) { ElMessage.success('更新成功'); getData(); } else { ElMessage.error(res.data.msg); } } catch (error) { console.error('Error updating data:', error); } }; onMounted(getData); </script> <style scoped></style>

对应fetchMemberGradeData返回的数据如下:
{"code":1,"msg":"成功","exceptions":null,"traceId":null,"ediTraceId":null,"targetTraceId":null,"data":{"mbrgId":1,"owner":"first","name":"一级会员","price":9.90,"downloadPerdayLimit":5,"downloadTotalLimit":5,"createTm":"2024-04-21T15:38:33.000+0000","updateTm":"2024-04-21T15:38:38.000+0000","isDelete":"0","expireTm":6},"success":true}
但是最终页面上的名称都没有变为‘一级会员’

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant