VUE控制表格列名显示和隐藏
<el-table-column v-for="(item,index) in showTableColumn" :key="item.index" :align="item.align" :prop="item.prop"
:min-width="item.minWidth" :width="item.width" :label="item.label" v-if="item.isShow">
<template slot-scope="{ row }">
<div class="no-select">{{ row[item.prop] }}</div>
</template>
</el-table-column>
data(){
return {
showTableColumn: []
}
},
created() {
this.getYearMonth()
},
methods:{
getYearMonth(e) {
var that = this
var currentDate = new Date()
if (e) {
currentDate = new Date(e)
}
var year = currentDate.getFullYear()
var month = currentDate.getMonth()
month = month + 1
var lastDay = new Date(year, month, 0).getDate()
console.log("当前月份的天数:" + lastDay)
var columnArr = []
for (var i = 1; i <= lastDay; i++) {
var day = i > 9 ? i : '0' + i
columnArr.push({
index: i,
prop: 'type-' + day,
label: year + '-' + month + '-' + day,
width: "100",
align: "center",
isShow: false
})
}
that.showTableColumn = columnArr
}
}