vue使用iVew表格插件 + Sortable.js进行拖拽,拖拽后表格表头数据显示不对怎么解决?

<template>
  <Table :columns="col" row-key="id" :data="tableData"></Table>
</template>
<script>
import Sortable from "sortablejs";
export default {
  props: {
    tableData: Array,
    col: Array
  },
  mounted() {
    this.columnDrop();
  },
  methods: {
    // 列拖拽
    columnDrop() {
      const wrapperTr = document.querySelector(".ivu-table-header tr");
      Sortable.create(wrapperTr, {
        animation: 150,
        delay: 0,
        onEnd: evt => {
          const oldItem = this.col[evt.oldIndex];
          this.col.splice(evt.oldIndex, 1);
          this.col.splice(evt.newIndex, 0, oldItem);
        }
      });
    }
  }
};
</script>

目前效果是可以进行拖拽,但是拖拽之后会出现显示错误,数据对应不上,但是打印出的数据是正确的,请问一下这种情况下如何解决?
image.png
image.png

阅读 5.6k
3 个回答

看起来像是动态响应的问题,最后一句改成这样试试看?

this.col.splice(evt.newIndex, 0, JSON.parse(JSON.stringify(oldItem)))
新手上路,请多包涵

this.col.splice(evt.newIndex, 0, this.col.splice(evt.oldIndex, 1)[0]);
var newArray1 = this.col.slice(0);
this.col = [];
this.$nextTick(function () {

this.col = newArray1;

});

这样设置表头与表里面的内容就行了,亲测有效

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题