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'
    }
  },
相关推荐
集成显卡27 分钟前
Bun v1.3.6 发布:内置 Tarball 归档支持、JSONC 解析、Bundle 分析增强等重磅更新!
javascript·新版本·bun.js
奔跑的web.37 分钟前
TypeScript Enum 类型入门:从基础到实战
前端·javascript·typescript
盐真卿1 小时前
python2
java·前端·javascript
梦梦代码精1 小时前
BuildingAI vs Dify vs 扣子:三大开源智能体平台架构风格对比
开发语言·前端·数据库·后端·架构·开源·推荐算法
刘一说1 小时前
Vue3 组合式 API(Composition API):逻辑复用的革命性实践
vue.js·vue
seabirdssss2 小时前
《bootstrap is not defined 导致“获取配置详情失败”?一次前端踩坑实录》
前端·bootstrap·html
kgduu2 小时前
js之表单
开发语言·前端·javascript
摘星编程3 小时前
React Native for OpenHarmony 实战:Picker 选择器组件详解
javascript·react native·react.js
摘星编程4 小时前
React Native for OpenHarmony 实战:VirtualizedList 虚拟化列表
javascript·react native·react.js
谢尔登4 小时前
Vue3 响应式系统——computed 和 watch
前端·架构