elementui + vue2实现表格行的上下移动

文章讲述了如何在Vue应用中利用ElementUI组件构建一个具有自增序号且支持行上下移动功能的表格,包括`scope.$index`在事件处理中的应用以及如何处理分页不影响序号的情况。
摘要由CSDN通过智能技术生成

scope.$index 获取当前点击的序号

<el-dialog
    append-to-body
    title="条件编辑"
    :visible.sync="dialogVisible"
    width="60%"
>
    <el-table :data="data1" border style="width: 100%">
        <el-table-column type="index" label="序" width="100" align="center">
        </el-table-column>
        <el-table-column prop="edit" label="" align="center">
            <template slot-scope="scope">
               <el-button
                  :disabled="scope.$index === 0"
                  plain
                  type="primary"
                  icon="el-icon-top"
                  @click="moveUp(scope.$index, scope.row)"
                  >上移</el-button>
                <el-button
                :disabled="scope.$index === data1.length - 1"
                  plain
                  type="primary"
                  icon="el-icon-bottom"
                  @click="moveDown(scope.$index, scope.row)"
                  >下移</el-button>
             </template>
        </el-table-column>
     </el-table>
</el-dialog>
 this.data1 是列表的总数据

// 上移
moveUp(index, row) {
    if(index !== 0){
      const currentRow = row;
      this.data1.splice(index, 1);
      this.data1.splice(index - 1, 0, currentRow);
     }
},
// 下移
moveDown(index, row) {
    if(index !== this.data1.length-1){
      const currentRow = row;
      this.data1.splice(index, 1);
      this.data1.splice(index + 1, 0, currentRow);
     }
},

如果不想受分页影响

表格第一列为自增序号(不受分页影响)

<el-table-column label="序号" width="70" align="left">
    <template slot-scope="scope">
       {{ (scope.$index+1)+(currentPage-1)*pageSize }}
    </template>
</el-table-column>

  --------->

elementui + vue2实现表格行的上下移动_<el-button @click="moveup(scope.$index)">up</el-bu-CSDN博客

VUE element-ui之table表格自增序号(前端实现)_vue前端增加一个序号列-CSDN博客

  • 11
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值