el-table 动态生成表头和el-input
时间: 2023-11-11 20:00:45 浏览: 102
可以使用 v-for 指令动态生成 el-table 的表头,同时在表格中使用 el-input 组件。具体实现可以参考以下代码:
<template>
<el-table :data="tableData">
<el-table-column v-for="(column, index) in tableColumns" :key="index" :prop="column.prop" :label="column.label">
<template slot-scope="scope">
<el-input v-model="scope.row[column.prop]"></el-input>
</template>
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableColumns: [
{ label: '姓名', prop: 'name' },
{ label: '年龄', prop: 'age' },
{ label: '性别', prop: 'gender' }
],
tableData: [
{ name: '张三', age: 18, gender: '男' },
{ name: '李四', age: 20, gender: '女' },
{ name: '王五', age: 22, gender: '男' }
]
}
}
}
</script>
在上面的代码中,我们使用 v-for 指令遍历 tableColumns 数组,动态生成表头。同时,在 el-table-column 的模板中使用 el-input 组件,实现表格中的输入框。
相关推荐
















