<script> import FormEdit from './FormEdit.vue'; import FormCreate from…
- Usercode
<el-button @click="loadData">Load data</el-button> <el-button @click="handleCreate">Add new medals</el-button> <el-table :data="tableData" style="width: 100%"> <el-table-column prop="pk" label="pk" width="80" sortable /> <el-table-column prop="nationality" label="Nationality" width="300" sortable /> <el-table-column prop="name" label="Name" width="140" sortable /> <el-table-column prop="goldMedal" label="Gold Medal" width="160" sortable /> <el-table-column prop="silverMedal" label="Silver Medal" width="160" sortable /> <el-table-column prop="bronzeMedal" label="Bronze Medal" width="160" sortable /> <el-table-column label="Operations"> <template #default="scope"> <el-button type="primary" size="mini" plain @click="handleEdit(scope.$index, scope.row)">Edit</el-button> <el-button type="danger" size="mini" plain @click="handleDelete(scope.$index, scope.row)">Delete</el-button> </template> </el-table-column> </el-table> <form-edit ref="formEdit" @cancel="handleFormEditCancel" @confirm="handleFormEditConfirm"> </form-edit> <!-- @cancel is ignored --> <form-create ref="formCreate" @confirm="handleFormCreateConfirm"> </form-create>add a total medal to each row
- Assistant
- User
when i create a new one the total will no show immediately but need to refresh
- Assistant
If the total medals column isn't reflecting the new entry's total immediately after creation, it's likely due to the fact that the
totalMedalsproperty is not being calculated and added to the new entry in thehandleFormCreateConfirmmethod. To address this, you need to ensure that whenever you modify the data in your table (especially when adding a new entry), you calculate thetotalMedalsproperty for that entry before adding it totableData.In
handleFormCreateConfirm, right after receiving the response from the server but before pushing the new data into , you should calculate the . Here's how you can resolve the issue: - User
may you make it load data automatically when needed?
- Assistant
- User
it seems curd's c, u and d need:
code.then((data) => { this.tableData = data.map(item => ({ ...item, totalMedals: item.goldMedal + item.silverMedal + item.bronzeMedal })); });any way to make this reusable?
- Assistant