element问题记录

1、table组件右侧固定区域过长,导致滚动条右侧滚动不了的问题解决

.dialogEditor{
  ::v-deep .el-table__fixed, ::v-deep .el-table__fixed-right{
    height: calc(100% - 9px) !important;
  }
}

2、按钮点击后颜色不能恢复的问题

.el-button--primary {
  color: #fff;
  background-color: #ff6a6c !important;
  border-color: #ff6a6c !important;
  &:hover {
    color: #fff;
    background-color: #ff6a6c !important;
    border-color: #ff6a6c !important;
    opacity: 0.6;
  }
  &:active {
    color: #fff;
    background-color: #ff6a6c !important;
    border-color: #ff6a6c !important;
    opacity: 0.8;
  }
}

3、更新table数据源后,滚动条会回到顶部的问题解决

 this.savedScrollTop = this.$refs.draggableTable.$el.querySelector(
        "div.el-table__body-wrapper"
      ).scrollTop;
 this.tableData = [...arr];
setTimeout(() => {
            this.$refs.draggableTable.$el.querySelector(
              "div.el-table__body-wrapper"
            ).scrollTop = this.savedScrollTop;
          }, 0);

4、table组件序号列拖拽排序

<el-table
      height="calc(100vh - 280px)"
      ref="draggableTable"
      v-loading="loading"
      :data="tableData"
      style="width: 100%; margin-top: 15px"
      border
      stripe
      highlight-current-row
    >XXXXXXX</el-table>
import Sortable from "sortablejs";
 mounted() {
    // 初始化表格
    this.loadData();
    // 初始化可排序表格
      this.initSortable();    
  },
initSortable() {
      const el = this.$refs.draggableTable.$el.querySelector(
        ".el-table__body-wrapper tbody"
      );
      this.sortable = Sortable.create(el, {
        handle: ".el-table__row td:nth-child(1)",
        onEnd: this.onSortEnd,
      });
    },
 /**
     * 当拖拽结束时触发的回调函数
     *
     * @param newIndex 新的索引位置
     * @param oldIndex 旧的索引位置
     */
    onSortEnd({ newIndex, oldIndex }) {
      this.savedScrollTop = this.$refs.draggableTable.$el.querySelector(
        "div.el-table__body-wrapper"
      ).scrollTop;
      //console.log("==============", this.savedScrollTop);
      console.log(newIndex, oldIndex);
      let arr = JSON.parse(JSON.stringify(this.tableData));
      let sortArr = [];
      let bool = true;
      let max = Math.max(oldIndex, newIndex);
      let min = Math.min(oldIndex, newIndex);
      const movedItem = arr.splice(oldIndex, 1)[0];
      arr.splice(newIndex, 0, movedItem);
      this.$nextTick(() => {
            this.tableData = [...arr];
      })
    },
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.Typescript中的&理解 参数中的 & 表示props对象同时拥有了TagManagementState...
    Lethe35阅读 7,682评论 0 1
  • 前端经典面试题: 1、(前端面试题)https://zhuanlan.zhihu.com/p/84212558?f...
    who_are_you_阅读 376评论 0 2
  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 12,960评论 2 59
  • 在我们使用element进行开发的时候,有时会出现一些奇怪的问题,这些问题有可能是框架本身的缺陷,也有可能是我们使...
    kevision阅读 1,667评论 0 1
  • 主要是记录一些在使用Element-ui 组件时,耗费时间去解决的一些问题。 1. 表格渲染出现列项数据重叠,错位...
    z_hboot阅读 339评论 0 1