vue列表拖拽

在这里插入图片描述

 //  模板部分
 <el-table
          v-if="cinemaLabels"
          :data="cinemaLabels"
          drag="true"
          class="tableList"
          border
          style="margin: 5px 0 20px 140px; width: 67%"
          row-key="order"
        >
          <el-table-column prop="order" type="index" label="ID" width="80px"/>
          <el-table-column :formatter="formatName" prop="name" label="标签名称"/>
          <el-table-column :formatter="formatType" prop="tagType" label="标签类型"/>
          <el-table-column fixed="right" label="操作" width="230px">
            <template slot-scope="scope">
              <el-button
                type="primary"
                size="mini"
                @click="deleteCinemaTip(scope.row)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
   // script 部分
    data() {
	    return {
	    	 cinemaLabels: [],
	    }
    }
  methods: {
	// 行拖拽
    rowDrop() {
      const tbody = document.querySelector('.tableList .el-table__body-wrapper tbody')
      const _this = this
      Sortable.create(tbody, {
        draggable: '.el-table__row',
        onEnd({ newIndex, oldIndex }) {
          const tab = JSON.parse(JSON.stringify(_this.cinemaLabels))
          const currRow = tab[oldIndex]
          tab.splice(oldIndex, 1)
          tab.splice(newIndex, 0, currRow)
          _this.cinemaLabels = tab
          setTimeout(() => {
            _this.$nextTick(() => {
              _this.showForm.storeTags = _this.cinemaLabels
            })
          }, 5)
        }
      })
    },
      columnDrop() {
      const wrapperTr = document.querySelector('tableList tr')
      const _this = this
      Sortable.create(wrapperTr, {
        animation: 180,
        delay: 0,
        onEnd: (evt) => {
          const dropCol = JSON.parse(JSON.stringify(_this.dropCol))
          const oldItem = dropCol[evt.oldIndex]
          dropCol.splice(evt.oldIndex, 1)
          dropCol.splice(evt.newIndex, 0, JSON.parse(JSON.stringify(oldItem)))
          setTimeout(() => {
            _this.dropCol = JSON.parse(JSON.stringify(dropCol))
          }, 5)
        }
      })
    },
    deleteCinemaTip(info) {
      this.cinemaLabels.map((item, index) => {
        if (item.name === info.name) {
          this.cinemaLabels.splice(index, 1)
        }
      })
      this.showForm.storeTags = this.cinemaLabels
    },
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值