element-ui使用table插件获取当前行下标和内容

直接上代码:

<el-table-column label="操作" align="center" class="change">
                    <template scope="scope">
                        <span class="c_button" @click="edit(scope.$index, scope.row)">编辑</span>
                        <span class="c_button" @click="del(scope.$index)">删除</span>
                    </template>
</el-table-column>

 // 编辑按钮
        edit(index, data) {
            console.log(index);
            console.log(data);
            console.log('编辑按钮');
        },
 // 删除按钮
        del(index) {
            console.log(index);
            console.log('删除按钮');
        },
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在 Vue.js 中,获取 el-table 下标可以使用 prop 属性中的 $index 变量。$index 变量是在 el-table使用 v-for 指令时自动提供的。$index 变量表示当前循环到的索引值,它的值与数组索引值一一对应。 例如,在el-table 中绑定 v-for 指令如下: ```html <el-table :data="tableData"> <el-table-column label="姓名" prop="name"></el-table-column> <el-table-column label="年龄" prop="age"></el-table-column> <el-table-column label="性别" prop="gender"></el-table-column> </el-table> ``` 在这个模板中,我们可以通过在模板中插入一个自定义列来获取索引值: ```html <el-table :data="tableData"> <el-table-column type="index" label="序号"></el-table-column> // 获取序号列 <el-table-column label="姓名" prop="name"></el-table-column> <el-table-column label="年龄" prop="age"></el-table-column> <el-table-column label="性别" prop="gender"></el-table-column> <el-table-column label="操作"> <template slot-scope="scope"> // scope是当前数据对象 <button @click="handleEdit(scope.$index)">编辑</button> // 获取el-table下标 </template> </el-table-column> </el-table> ``` 在这个例子中,我们使用了 slot-scope 来获取作用域对象,作用域对象中有一个 $index 变量,可以直接用来获取当前的索引值。 另外,在 el-table 父节点实例中也可以通过 this.$refs.table.$children 获取 el-table 下标。需要注意的是,由于 el-table 可能包含多个子组件,所以 $children 返回的是数组。如果只有一个 el-table 子组件,则可以使用如下代码获取: ```javascript let index = this.$refs.table.$children[0].$index ``` 总之,在 Vue.js 中获取 el-table 下标的方法有很多,上述方法都是比较常用的方法。根据具体场景和需求,选择合适的方法来获取下标即可。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值