本文主要是介绍利用sortablejs实现拖拽排序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import Sortable from "sortablejs";
created() {//禁止火狐拖拽进行搜索document.body.ondrop = function(event){event.preventDefault();event.stopPropagation();}}// 打开对话框的时候调用下openCustomDialog(){this.rowDrop()}// 行拖拽
rowDrop() {this.$nextTick(() => {this.sortable1 = Sortable.create(document.querySelector(".form_table .el-table__body-wrapper tbody"),{handle: ".drag-btn",onEnd: ({ newIndex, oldIndex }) => {this.tableData.splice(newIndex,0,this.tableData.splice(oldIndex, 1)[0]);var newArray = this.tableData.slice(0);this.tableData = [];this.$nextTick(function () {this.tableData = newArray;});},});});
},
<el-dialogtitle="自定义":visible.sync="customDialogVisible"v-if="customDialogVisible":append-to-body="true"width="20%"><el-table:data="tableData"class="form_table"borderfithighlight-current-row><el-table-columnprop="sort"label="拖拽更换顺序"align="center"><i class=" el-icon-sort drag-btn"></i></el-table-column><el-table-columnprop="desc"label="图片类型"align="center"></el-table-column></el-table><div class="btns"><el-button @click="cancelCustomDialog">取消</el-button><el-button type="primary" @click="confirmCustomDialog" :loading="loading">确定</el-button></div></el-dialog>
<style scoped>
//悬停出现鼠标
.drag-btn{cursor: pointer;
}
</style>
注意:drag-btn 这个可以修改,但是上下要对应上
这篇关于利用sortablejs实现拖拽排序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!