vue/element表格拖動排序的實現——sortablejs
阿新 • • 發佈:2020-12-29
目的
實現頁面上的表格,能夠拖動排序
實現
npm install sortablejs --save
- 引入sortablejs
import Sortable from 'sortablejs';
- 儲存sortablejs示例
data() {
return {
sortable: {}
}
},
mounted() {
this.rowDrop();
}
methods: {
rowDrop() {
const tbody = document.querySelector('.el-table__body-wrapper tbody' );
this.sortable = Sortable.create(tbody, {
onEnd: evt => {//拖動結束時觸發,我在這裡呼叫介面,改變後臺的排序
if (evt.oldIndex !== evt.newIndex) {
......
}
}
});
},
}