vue使用sortable在更新排序后更新数据的顺序
该项目是使用混合代码的PHP项目,用了VUE,使用了sortable对数据进行手动排序,存在的问题是html更新排序后,需要对VUE的数据进行更新,如下是JS片段:
//排序功能
let sortable = new Sortable(this.$refs.sortTable, {
animation: 150,
handle: '.sort-handler',
filter: '.sort-filter',
draggable: '.sort-item',
onUpdate: function (evt) {
// console.log(evt);
// console.log(evt.newIndex , evt.oldIndex)
const {groups} = vm
if (evt.newIndex > evt.oldIndex) {
groups.splice(evt.newIndex, 0, groups[evt.oldIndex - 1])
groups.splice(evt.oldIndex - 1, 1)
} else {
groups.splice(evt.newIndex - 1, 0, groups[evt.oldIndex - 1])
groups.splice(evt.oldIndex, 1)
}
vm.saved = false
}
});版权属于:Joyber
本文链接:https://blog.qqvbc.com/default/1233.html
转载时须注明出处及本声明