vuejs+elementui实现表格某一列的宽度为这一列最长数据的宽度

1、页面结构(el-table)

  <el-table :data="tableData" class="table" >
    <el-table-column label="任务状态" :width="flexWidth(tableData)*110">    
      <template slot-scope="scope">
                      <div>
                          <div v-for="(item,index) in scope.row.taskFlowVos" :key="item.id" >
                              <span>{{item.name}}</span>
                          </div>
                      </div>
                 </template>
        </el-table>
2、实现逻辑
  想法:获取表格数据tableData中的taskFlowVos最大长度值,并且1个长度值宽度为110px
  实现:
    flexWidth(data){
              let arr = [];
              if(data.length > 0){
                  data.map((item)=>{
                      arr.push(item.taskFlowVos.length)
                  })
              }else{
                  arr.push(1)
              }
              return Math.max.apply(null, arr)
          }
posted @ 2022-07-07 16:28  我爱敲代码0000  阅读(582)  评论(0编辑  收藏  举报