表单项上移、下移、交换位置

2023-01-30  本文已影响0人  RichieQ
            //import draggable from 'vuedraggable'
            // 拖拽
            onDragEnd(e) {
                if (e.newIndex != e.oldIndex) {
                    let listData = this.formData.listData;
                    listData[e.newIndex] = listData.splice(e.oldIndex, 1, listData[e.newIndex])[0];
                }
            },
            // 上移
            onUpGo(index) {
                let listData = this.formData.listData;
                if (index !=0 ) {
                    listData[index] = listData.splice(index-1, 1, listData[index])[0];
                } else {
                    listData.push(listData.shift());
                }
            },
            // 下移
            onDownGo(index) {
                let listData = this.formData.listData;
                if (index != listData.length - 1) {
                    listData[index] = listData.splice(index+1, 1, listData[index])[0];
                } else {
                    listData.unshift(listData.splice(index, 1))[0];
                }
            },
上一篇下一篇

猜你喜欢

热点阅读