• element 表格拖拽保存插件


    这是以前看着一篇文章

    1.下载包
    npm install sortablejs --save
    2.在页面中引入,或者全局引入
    import Sortable from ‘sortablejs’
    3.在template中

    <div id="second">
      <el-table
        class="threeTable"
        :style="{'height':tableData.length === 0 ? '100px' : 'auto'}"
        :data="tableData"
        stripe
        style="width: 100%;"
        highlight-current-row
        :header-cell-style="headerCellStyle"
        row-key="proCode">
        <el-table-column type="index" label="序号" width="58"></el-table-column>
        <el-table-column prop="proCode" label="供方编码"></el-table-column>
        <el-table-column prop="proDesc" label="供方名称"></el-table-column>
        <el-table-column label="操作" width="80">
          <template slot-scope="scope">
          <el-tooltip class="tree-item" effect="dark" content="删除" placement="top">
            <el-button type="text" class="" @click="deleteTable(scope.row, scope.$index)"><icon-svg icon-class="iconshanchu" /></el-button>
          </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </div>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    在script中

    <script>
    	mounted () {
    		this.rowDrop()
    	},
    	methods: {
    	   // 行拖拽
           rowDrop () {
            const tbody = document.querySelector('#second .el-table__body-wrapper tbody')
            const _this = this
            Sortable.create(tbody, {
              onEnd ({newIndex, oldIndex}) {
                const currRow = _this.tableData.splice(oldIndex, 1)[0]
                _this.tableData.splice(newIndex, 0, currRow) // _this.tableData换成自己的表格即可
              }
            })
          },
    	}
    </script>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
  • 相关阅读:
    【Vue】自定义指令
    (七)C++中实现argmin与argmax
    阻抗与导纳的理解
    5G及其后的5G非地面网络:趋势和研究挑战-HARQ部分
    Webpack最简单的流程理解
    Pandas loc与iloc
    行业分析网站-网站分析软件-免费网站详细数据分析软件
    java游戏服务器性能压测神器:jprofiler
    1. Springboot集成Mybatis
    多线程的线程同步(即上锁)
  • 原文地址:https://blog.csdn.net/weixin_41166682/article/details/106349273