鍍金池/ 問答/HTML5  HTML/ element-ui的el-table如何在html中引用當前行的索引

element-ui的el-table如何在html中引用當前行的索引

需求:想給el-table渲染出的某列td增加id屬性,id的值為 id=“xxx-{{index}}” index是當前行的索引
怎么解決. . .

下面是我的嘗試:

<el-table-column
        :id="index"
        prop="created_at"
        label="日期"
        sortable
        :formatter="formatterDate"
        width="180"
        align="center">
</el-table-column>

失敗,index未定義

回答
編輯回答
舊時光

可以嵌入一個<template> 設置屬性slot-scope="scope",索引值就可以這樣取到 scope.$index

如下示例

<el-table-column
      fixed="right"
      label="操作"
      width="120">
      <template slot-scope="scope">
        <el-button
          @click.native.prevent="deleteRow(scope.$index, tableData4)"
          type="text"
          size="small">
          移除
        </el-button>
 </template>
2017年12月25日 13:04
編輯回答
帥到炸

試試這個
圖片描述

可以看看官方文檔:http://element-cn.eleme.io/#/...

2018年1月8日 21:32