该项目是使用混合代码的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
                    }
                });

标签: none

添加新评论