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'
    }
  },
相关推荐
二哈喇子!20 分钟前
使用NVM下载Node.js管理多版本
前端·npm·node.js
GGGG寄了1 小时前
HTML——文本标签
开发语言·前端·html
摘星编程1 小时前
在OpenHarmony上用React Native:ActionSheet确认删除
javascript·react native·react.js
2501_944521591 小时前
Flutter for OpenHarmony 微动漫App实战:推荐动漫实现
android·开发语言·前端·javascript·flutter·ecmascript
Amumu121382 小时前
Vue核心(三)
前端·javascript·vue.js
CoCo的编程之路2 小时前
2026 前端效能革命:如何利用智能助手实现“光速”页面构建?深度横评
前端·人工智能·ai编程·comate·智能编程助手·文心快码baiducomate
RFCEO2 小时前
HTML编程 课程五、:HTML5 新增语义化标签
前端·html·html5·跨平台·语义化标签·可生成安卓/ios·html最新版本
Irene19913 小时前
JavaScript中,为什么需要手动清理事件
javascript·手动清理事件监听器
摘星编程3 小时前
OpenHarmony环境下React Native:Zustand持久化存储
javascript·react native·react.js
2501_944521593 小时前
Flutter for OpenHarmony 微动漫App实战:图片加载实现
android·开发语言·前端·javascript·flutter·php