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'
    }
  },
相关推荐
计算机毕设VX:Fegn08957 小时前
计算机毕业设计|基于springboot + vue图书商城系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·课程设计
哆啦A梦15887 小时前
商城后台管理系统 03 登录布局
javascript·vue.js·elementui
曼巴UE57 小时前
UE FString, FName ,FText 三者转换,再次学习,官方文档理解
服务器·前端·javascript
selt7918 小时前
Redisson之RedissonLock源码完全解析
android·java·javascript
行走的陀螺仪8 小时前
高级前端 Input 公共组件设计方案(Vue3 + TypeScript)
前端·javascript·typescript·vue·组件设计方案
一颗不甘坠落的流星9 小时前
【Antd】基于 Upload 组件,导入Json文件并转换为Json数据
前端·javascript·json
LYFlied9 小时前
Vue2 与 Vue3 虚拟DOM更新原理深度解析
前端·javascript·vue.js·虚拟dom
Lucky_Turtle9 小时前
【Node】npm install报错npm error Cannot read properties of null (reading ‘matches‘)
前端·npm·node.js
小飞侠在吗9 小时前
vue shallowRef 与 shallowReacitive
前端·javascript·vue.js