// 模板部分
<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
},
}
vue列表拖拽
最新推荐文章于 2024-06-19 15:39:02 发布