【问题标题】:vue element-ui get index of table rowvue element-ui 获取表格行的索引
【发布时间】:2019-12-25 08:45:18
【问题描述】:

我只想在表格列的第一行添加一个按钮(在示例代码中标有“选项”)。有没有简单的方法来检查 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>

【问题讨论】:

    标签: vue.js html-table row element-ui


    【解决方案1】:

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

    <div v-if="scope.$index === 0">
    

    【讨论】:

    • 如果对数据进行过滤或排序会怎样?我认为这将不再起作用......
    【解决方案2】:

    vue template & scope.$index

    我的解决方案:

     <el-table
        :data="tableData"
        border
        class="app-downlaod-guide-table"
        style="width: 100%">
        <el-table-column
          v-for="({
            prop,
            label,
            align,
            width,
            slot,
          }, i) in channelClomuns"
          :key="prop + i"
          :prop="prop"
          :width="width"
          :align="align"
          :label="label">
          <template
            slot-scope="scope"
            v-if="prop === `putLink`">
            <a
              target="_blank"
              href="tableData[scope.$index].putLink">
              {{tableData[scope.$index].putLink}}
            </a>
          </template>
        </el-table-column>
      </el-table>
    
    
    

    【讨论】:

    • 如果对数据进行过滤或排序会怎样?我认为这将不再起作用......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-08
    • 2021-06-01
    • 2021-11-05
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 2019-12-15
    相关资源
    最近更新 更多