vue element-ui 获取表格行索引

onc*_*nce 3 row html-table vue.js element-ui

我只想向表格列的第一行添加一个按钮(在示例代码中标有“选项”)。有没有简单的方法来检查 v-if 的行索引v-if="scope.row.index === 0"scope.row.index不会在这里工作。

<el-table :data="mydata">
<!-- more columns -->
  <el-table-column prop="option" label="Option">
    <template slot-scope="scope">
      <div v-if="scope.row.index === 0">
        <el-row>
          <el-col>
            <el-input v-model="scope.row.option"/>
          </el-col>
          <el-col>
            <el-button @click="">Check</el-button>
          </el-col>
      </el-row></div>
      <div v-else>
        <el-input v-model="scope.row.option" />
      </div>
    </template>
  </el-table-column>
<!-- more columns -->
</el-table>
Run Code Online (Sandbox Code Playgroud)

onc*_*nce 9

我通过使用$index变量找到了解决方案,该变量是当前行的索引。

<div v-if="scope.$index === 0">
Run Code Online (Sandbox Code Playgroud)