这是代码<template> <a-table :columns="columns" :data-source="dataSource" row-key="key" :editable="true"> <template slot="heJin_AI" slot-scope="text, record, index"> <a-input v-model="record.heJin_AI.heJin_Mn1" /> <a-input v-model="record.heJin_AI.heJin_Mn2" /> <a-input v-model="record.heJin_AI.heJin_Mn3" /> </template> <template slot="heJin_CCC" slot-scope="text, record, index"> <a-input v-model="record.heJin_CCC.heJin_CCC1" /> <a-input v-model="record.heJin_CCC.heJin_CCC2" /> <a-input v-model="record.heJin_CCC.heJin_CCC3" /> </template> <template slot="operation" slot-scope="text, record, index"> <template v-for="item in columns"> <a-icon type="minus-square" v-if="item.editable" @click="addRow(item.key)" /> <span v-else></span> </template> </template> </a-table> </template> <script> export default { data() { return { dataSource: [ { key: '1', id: 1, heJin_AI: { heJin_Mn1: '数据1', heJin_Mn2: '数据2', heJin_Mn3: '数据3', }, }, { key: '2', id: 2, heJin_AI: { heJin_Mn1: '数据3', heJin_Mn2: '数据4', heJin_Mn3: '数据5', }, }, { key: '3', id: 3, heJin_CCC: { heJin_CCC1: '数据33333', heJin_CCC2: '数据44444', heJin_CCC3: '数据555555', }, }, ], columns: [ { title: '操作', dataIndex: 'operation', scopedSlots: { customRender: 'operation' }, align: 'center', }, { title: 'ID', dataIndex: 'id', key: 'id', }, { title: 'heJin_AI', dataIndex: 'heJin_AI', key: 'heJin_AI', scopedSlots: { customRender: 'heJin_AI' }, editable: true, }, { title: 'heJin_CCC', dataIndex: 'heJin_CCC', key: 'heJin_CCC', scopedSlots: { customRender: 'heJin_CCC' }, editable: true, }, ], } }, methods: { addRow(key) { console.log(key) const maxKey = Math.max(...this.dataSource.map((item) => parseInt(item.key))) const newRow = { key: (maxKey + 1).toString(), id: maxKey + 1, heJin_AI: { heJin_Mn1: '', heJin_Mn2: '', heJin_Mn3: '', }, heJin_CCC: { heJin_CCC1: '', heJin_CCC2: '', heJin_CCC3: '', }, } this.dataSource = [...this.dataSource, newRow] console.log(this.dataSource) }, }, } </script> <style> </style>
时间: 2024-03-19 11:43:04 浏览: 96
这是能帮助用户处理数据的代码
根据您提供的代码,可能是因为在第一个数据对象中没有定义 'heJin_CCC' 属性,但是在模板中尝试访问该属性。您可以尝试在第一个数据对象中定义 'heJin_CCC' 属性,或者在模板中使用条件渲染指令来避免访问未定义的属性,例如:
```
<template slot="heJin_CCC" slot-scope="text, record, index">
<a-input v-if="record.heJin_CCC" v-model="record.heJin_CCC.heJin_CCC1" />
<a-input v-if="record.heJin_CCC" v-model="record.heJin_CCC.heJin_CCC2" />
<a-input v-if="record.heJin_CCC" v-model="record.heJin_CCC.heJin_CCC3" />
</template>
```
您还可以检查所有数据对象,确保它们都具有相同的属性和结构。如果问题仍然存在,请提供更多上下文和错误信息以获得更具体的帮助。
阅读全文