el-table动态表格,行列都为动态数据
<template>
<el-table
:data="tableData"
style="width: 100%">
<el-table-column label="序号" width="50">
<template slot-scope="scope">{{scope.$index + 1}}</template>
</el-table-column>
<el-table-column
v-for="(item,index) in titleData
:key="index"
:lable="item"
:prop="keysData[index]"">
</el-table-column>
<el-table-column label="结果" width="50">
<template slot-scope="scope">
<el-input v-model="scope.row.result"></el-input>
</template>
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [{
id001: '电流',
id002: '电压',
id003: '电阻'
}, {
id001: '0.1',
id002: '0.2',
id003: '0.3'
}, {
id001: '0.11',
id002: '0.22',
id003: '0.33'
}, {
id001: '0.111',
id002: '0.222',
id003: '0.333'
}],
titleData : [],
keysData : []
}
},
mounted(){
this.divisor();
},
methods:{
divisor(){
var object = this.tableData[0];
this.titleData = Object.values(object);
this.keysData = Object.keys(object);
this.tableData = this.tableData.splice(1);
}
}
}
</script>