就一下代码块里面有注解了。。可以参考一下
主要是,你表格的表头是动态的,然后设置多少列,然后取你动态表头的数据,转换成map,取到你的中文,关联的数组下标。一一对应就可以弄成动态了!而且还是动态的宽度。可以达到俩列的长度,一个表头的值,然后可以拿第二个table做数据填充,不说了看图就行了,大家也是见过世面的!
<el-table
ref="one"
border
:data="[productWidth]"
:fit="false"
:header-cell-style="{borderTop : '2px solid #dfe6ec',borderLeft : '2px solid #dfe6ec',textAlign: 'center'}"
style="font-size: 12pt; "
>
<el-table-column align="center" :width="item.dataHeaderWidth" v-for="item in dataHeader" :key="item.prop":prop="item.prop":label="item.label">
</el-table-column>
</el-table>
为啥下列还要for循环添加一个列属性呢,因为第一列通常要有说明啥的,所以可以加一个说明达到效果
detectionCon(){
//检测表的查询条件
detectionConditionsList(this.queryParamsForm1).then(response => {
this.from3 = response.rows;
});
detectionBaseMetalList(this.queryParamsForm1).then(response => {
/* console.log(JSON.stringify(response.rows));*/
this.from1 = response.rows;
if(this.from1 == []){
alert("此母材已被完全加工!");
return;
}
///这里是设置动态表格多少列
this.from2Size = this.from1[this.from1.length-1].frontEndNumber;
//这里是设置动态表格,从列转行
this.temp = new Array(this.from1.length).fill('').map((_, index) => 'col' + index)
let orderab = this.from1.map(item => item.orderabSign)
let clientName = this.from1.map(item => item.clientName)
let numberSlit = this.from1.map(item => item.numberSlit)
this.dataHeader = this.temp.map((item, index) => ({
prop: item,
label: clientName[index]+(orderab[index] != null && orderab[index] !='' ?"("+orderab[index]+")":'') ,
dataHeaderWidth: numberSlit[index]*80 + "px;"
}))
this.dataHeader.unshift({prop: 'clientName', label: '客户',dataHeaderWidth: 2*80 + "px;"
})
//这里是设置表格内容
for (let i in this.from1) {
/* console.log(JSON.stringify(i ));*/
if(i == 0){
this.productWidth['clientName'
] = '成品宽度'
}
this.productWidth['col' + i
] = this.from1[i
].productWidth
}
//设置表格长度
for (let i in this.from1) {
if(i == 0){
this.dataHeaderWidth['clientName'
] = 2*80 + "px;"
}
//"'width:' + percent + '%'"
this.dataHeaderWidth['col' + i
] = this.from1[i].numberSlit*80 + "px"
}
this.$forceUpdate();
/* console.log(JSON.stringify(this.dataHeaderWidth ));
console.log(JSON.stringify(this.productWidth ));
console.log(JSON.stringify(this.dataHeader ));*/
});
}