在我们使用elementui的开发过程中肯定离不开使用table表格。但是当我们表格的内容特别多的时候我们就要写很多个 el-table-column标签 这样页面很不美观也比较难以维护
这里我们可以将 el-table-column标签里的内容抽取出来代码如下
salaryArr() {
let arr = [
{ label: "一级部门", field: "firstDeptName", width: "80" },
{ label: "二级部门", field: "secondDeptName", width: "80" },
{ label: "三级部门", field: "thirdDeptName", width: "80" },
{ label: "归集科目", field: "subject", width: "80" },
{ label: "岗位", field: "post", width: "80" },
{ label: "姓名", field: "employeeName", width: "80" },
{ label: "身份证号", field: "idNumber", width: "80" },
{ label: "工资总额", field: "total", width: "80" },
{ label: "车辆补贴总额", field: "carSubsidy", width: "80" },
{ label: "电脑补贴总额", field: "computerSubsidy", width: "80" },
{ label: "误餐补贴总额", field: "mealSubsidy", width: "80" },
{ label: "工龄工资总额", field: "seniorityPay", width: "80" },
{ label: "技能津贴总额", field: "skillSubsidy", width: "80" },
{ label: "公司社保", field: "companySecurityFee", width: "80" },
{ label: "公司公积金", field: "companyCorporateFee", width: "80" },
{ label: "五险一金合计", field: "companyTotalFee", width: "80" },
]
return arr
}
这里使用了计算属性 将这个数组给返回
后续要使用如下:
<el-table
:data="Salarydetails"
style="width: 100%"
>
<el-table-column
v-for="(item, index) in salaryArr"
:key="index"
:prop="item.field"
:label="item.label"
:min-width="item.width"
show-overflow-tooltip
/>
</el-table>
这样对比以往的写法就简洁很多,我们只需要维护数据即可不需要过多的再去修改dom