element el-table-column 循环

当table中表头太多了,然后不想一个一个写,可以用循环的方式写

先上个图
element el-table-column 循环_第1张图片
直接上代码

<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数据

 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",
        },
      ],

你可能感兴趣的:(view,element,vue.js,javascript,前端)