VUE+ElementUI实现table 行上下移动的效果

<div>
<el-table
        :data="URLModles"
        :show-header="false"
        highlight-current-row
        style="width: 100%"  @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          width="55px">
        </el-table-column>
        <el-table-column
          type="index"
          width="55px">
        </el-table-column>
        <el-table-column
          prop="expressCode"
          label="快递代码" width="100px">
        </el-table-column>
        <el-table-column
          prop="expressName"
          label="快递名称"  width="100px">
        </el-table-column>
        <el-table-column label="操作" >
          <template slot-scope="scope">
            <el-button
              size="mini"
              :disabled="scope.$index===0"
              @click="moveUp(scope.$index,scope.row)"><i class="el-icon-arrow-up"></i></el-button>
            <el-button
              size="mini"
              :disabled="scope.$index===(URLModles.length-1)"
              @click="moveDown(scope.$index,scope.row)"><i class="el-icon-arrow-down"></i></el-button>
            <el-button type="info" size="mini" round v-if="scope.$index===0">默认</el-button>
          </template>

        </el-table-column>
      </el-table>
</div>
<script>
  export default {
   
    data() {
      return {
        URLModles: [{
          index: '1',
          expressCode: 'SF',
          expressName: '顺丰快递',
          status: true,
        }, {
          index: '2',
          expressCode: 'YTO',
          expressName: '圆通快递',
          status: true,
        }, {
          index: '3',
          expressCode: 'UC',
          expressName: '优速快递',
          status: true,
        }],
        multipleSelection: []
      }
    },
    methods: {
     //选择复选框数据
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      //上移
      moveUp(index,row){
        var that = this;
        console.log('上移',index,row);
        console.log(that.URLModles[index]);
        if (index > 0) {
          let upDate = that.URLModles[index - 1];
          that.URLModles.splice(index - 1, 1);
          that.URLModles.splice(index,0, upDate);
        } else {
          alert('已经是第一条,不可上移');
        }
      },
    
      //下移
      moveDown(index,row){
        var that = this;
        console.log('下移',index,row);
        if ((index + 1) === that.URLModles.length){
          alert('已经是最后一条,不可下移');
        } else {
          console.log(index);
          let downDate = that.URLModles[index + 1];
          that.URLModles.splice(index + 1, 1);
          that.URLModles.splice(index,0, downDate);
        }
      }
    }
  }
</script>

最终的实现效果

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值