1.EemenetUi
https://element.eleme.cn/#/zh-CN/component/table
- 引入draggable
import draggable from 'vuedraggable'
- html
<el-table
id="otable"
:data="tableData"
border
row-key="id"
align="left"
height="70%"
>
<el-table-column v-for="(item, index) in col"
:key="`col_${index}`"
:prop="dropCol[index].prop"
:label="item.label">
</el-table-column>
</<el-table>
- JS
export default {
data() {
col: [
{
label: 'ID',
prop: 'id'
}
],
dropCol: [
{
label: 'ID',
prop: 'id'
}
],
},
methods:{
columnDrop() {
const wrapperTr = document.querySelector('.el-table__header-wrapper tr')
this.sortable = Sortable.create(wrapperTr, {
animation: 180,
delay: 0,
onEnd: evt => {
const oldItem = this.dropCol[evt.oldIndex]
this.dropCol.splice(evt.oldIndex, 1)
this.dropCol.splice(evt.newIndex, 0, oldItem)
}
})
}
}
}
2.IviewUi
https://www.iviewui.com/components/table
- HTML
<Table
border
:columns="columns"
:data="data"
:loading="loading"
height="550"
draggable
@on-drag-drop="drag"
v-show="show"
>
<template slot-scope="{ row }" slot="thumb">
<img :src="row.thumb" style="width:60px;padding:5px;height:80px" />
</template>
</Table>
- JS
methods:{
drag(a, b) {
this.data.splice(b, 1, ...this.data.splice(a, 1, this.data[b]));
},
}
3.如果问题请留言
如果问题请留言!!!