1. 程式人生 > 其它 >vue/element表格拖動排序的實現——sortablejs

vue/element表格拖動排序的實現——sortablejs

技術標籤:踩過的坑vueelementsortablejs

目的
實現頁面上的表格,能夠拖動排序
在這裡插入圖片描述


實現

  1. npm install sortablejs --save
  2. 引入sortablejs
import Sortable from 'sortablejs';
  1. 儲存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) { ...... } } }); }, }