1. 安装步骤
- Sortable.js是一款轻量级的拖放排序列表的js插件(虽然体积小,但是功能很强大)
- npm install sortablejs --save
- vue 在 main.js 中引入 import Sortable from "sortablejs"
- 在表格上添加row-key
- 官方Demo:rubaxa.github.io/Sortable/ **2.使用步骤
- 子最外层需套用一个div,指定类名
- 在 mounted 中进行调用
- 方法
const tbody = document.getElementById('sortableCard')
const that = this
Sortable.create(tbody, {
animation: 1000,
sort: true,
onEnd(evt) {
that.submitForm.goods.splice(evt.newIndex, 0, that.submitForm.goods.splice(evt.oldIndex, 1)[0])
var newArray = that.submitForm.goods.slice(0)
that.submitForm.goods = []
that.$nextTick(() => {
that.submitForm.goods = newArray
})
}
})
},
```