el-table纵向垂直表头

参考:https://www.jianshu.com/p/1f38eaffd070

javascript 复制代码
<el-table
  style="width: 100%"
  :data="getValues"
  :show-header="false"
  border
  :cell-style="cellStyle"
>
  <el-table-column
    v-for="(item, index) in getHeaders"
    :key="index"
    :prop="item"
  >
  </el-table-column>
</el-table>
javascript 复制代码
data() {
    return {
      headers: [
	      {
	        prop: 'date',
	        label: '套餐交割时间',
	      },
	      {
	        prop: 'name',
	        label: '价格(元/kWh)',
	      },
	    ],
	    tableData: [
	      {
	        date: '2016-05-02',
	        name: '王小虎',
	        address: '上海市普陀区金沙江路 1518 弄'
	      },
	      {
	        date: '2016-05-04',
	        name: '王小虎',
	        address: '上海市普陀区金沙江路 1517 弄'
	      },
	      {
	        date: '2016-05-01',
	        name: '王小虎',
	        address: '上海市普陀区金沙江路 1519 弄'
	      },
	      {
	        date: '2016-05-03',
	        name: '王小虎',
	        address: '上海市普陀区金沙江路 1516 弄'
	      }
	    ]
    }
  },
javascript 复制代码
computed: {
  getHeaders() {
    return this.tableData.reduce((pre, cur, index) => pre.concat(`value${index}`), ['title'])
  },
  getValues() {
    return this.headers.map(item => {
      return this.tableData.reduce((pre, cur, index) => Object.assign(pre, {['value' + index]: cur[item.prop]}), {'title': item.label,});
    });
  }
},
javascript 复制代码
methods: {
    cellStyle ({row, column, rowIndex, columnIndex}) {
      if(columnIndex===0) {
        return 'background: #F5F7FA; textAlign: center'
      }
      return 'textAlign: center'
    }
  },
相关推荐
IT_陈寒4 分钟前
Redis 高并发实战:我从 5000QPS 优化到 5W+ 的7个核心策略
前端·人工智能·后端
vortex524 分钟前
ASP vs ASP.NET vs ASP.NET Core:三代微软 Web 技术核心区别解析
前端·microsoft·asp.net
Apifox33 分钟前
如何在 Apifox 中使用「模块」合理地组织接口
前端·后端·测试
冰暮流星35 分钟前
css之flex属性
前端·css
若安程序开发44 分钟前
WEBweb前端OPPO手机商城网站项目
前端·智能手机
范德萨_1 小时前
JavaScript 实用技巧(总结)
开发语言·前端·javascript
李志2781 小时前
初识预加载
javascript
执携1 小时前
Vue Router (匹配当前路由的链接和类名配置)
前端·javascript·vue.js
若安程序开发1 小时前
web华为商城前端项目4页面
前端·华为
一枚前端小能手1 小时前
🏷️ HTML 属性参考 - 常用与全局属性的行为、兼容性与最佳实践
前端·javascript·html