关于前端:vue表格插槽-scopeindex-报错解决

通过数据的下标删除对应数据,表格点击删除的时候插槽scope中获取不到$index:

<table-column title="操作" fixed="right" width="80px" >
          <template slot-scope="scope">
            <el-button type="text" @click="remove(scope.$index)" >删除</el-button>
          </template>
</table-column>

method:
    remove(index){
      console.log(index)
      this.tableData.splice(index,1)
    }

插槽传参改用scope.$rowIndex:

<template slot-scope="scope">
<el-button type="text" @click="remove(scope.$rowIndex)" >删除</el-button>
</template>

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理