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未定义

阅读 7.7k
2 个回答

可以嵌入一个<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>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题