随笔 - 135  文章 - 0  评论 - 2  阅读 - 18万

table表格表头拖拽呼唤位置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<template>
  <div class="">
    <table>
      <thead class="el-table__header-wrapper has-gutter">
        <tr>
          <th v-for="(columns,index) in tablesColumns"
              :key="index"
              draggable="true"
              @dragstart="dragstartEvent(index)"
              @dragenter="dragenterEvent($event,columns)"
              @dragend="dragendEvent($event,columns)"
          >
            <label class="cell">{{ columns.name }}</label>
          </th>
        </tr>
      </thead>
      <tbody class="el-table__body">
        <tr>
          <td />
        </tr>
      </tbody>
    </table>
  </div>
</template>
 
<script>
export default {
  data() {
    return {
      tablesColumns: [{
 
        id: 0,
 
        name: '债券代码'
 
      }, {
 
        id: 1,
 
        name: '买卖方向'
 
      }, {
 
        id: 2,
 
        name: '量(万元)'
 
      }, {
 
        id: 3,
 
        name: '收益率'
 
      }]
 
    }
  },
  created() {},
  methods: {
    // 拖动开始--- 拿到当前目标对象的索引
 
    dragstartEvent(index) {
      this.dragStartIndex = index
    },
    // 拖动过程 --- 拿到结束后的对象
 
    dragenterEvent(ev, col) {
      this.dragEndColumn = col
    },
 
    // 拖动结束
 
    dragendEvent(ev, col) {
      this.tablesColumns.splice(this.dragEndColumn.id, 1, ...this.tablesColumns.splice(this.dragStartIndex, 1, this.tablesColumns[this.dragEndColumn.id])) // 这里用到了 数组对象的交换,id其实就是 索引下标
 
      for (let i = 0; i < this.tablesColumns.length; i++) { // 重新把id 整理一遍
        this.tablesColumns[i].id = i
      }
    }
 
  }
}
</script>
<style scoped lang='less'>
</style>

  

posted on   稳住别慌  阅读(107)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示