element el-table-column loop

When there are too many headers in the table, and you don’t want to write them one by one, you can write them in a loop

First go to the picture
insert image description here
and go directly to the code

<el-table :data="tableData">
      <div v-for="(col,ii) in cols" :key="ii">
        <el-table-column v-if="col.prop=='type'" :prop="col.prop" :label="col.label">
          <template scope="scope">
            <el-tag type="primary">{
    
    {
    
     scope.row.type == 1 ? '是' : '否' }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column v-else :prop="col.prop" :label="col.label">
        </el-table-column>
      </div>
    </el-table>


data data

 cols: [
        {
    
     label: "节点编号", prop: "node" },
        {
    
     label: "名称", prop: "name" },
        {
    
     label: "类型", prop: "type" },
        {
    
     label: "坐标", prop: "coordinate" }
      ],
      tableData: [
        {
    
    
          node: "0051",
          name: " 机库顶",
          type: "1",
          status: "正常",
          coordinate: "12.21,34.45,34.6",
        },
        {
    
    
          node: "0061",
          name: "机库门",
          type: "0",
          status: "低电",
          coordinate: "45.41,67.45,78.6",
        },
      ],

Guess you like

Origin blog.csdn.net/weixin_45289656/article/details/128854902