antd + vuedraggable 实现行拖动

antd+vuedraggable 实现行拖动

antd的弹窗默认是不支持拖拽的,所以...

app.vue文件

js 复制代码
<template>
  <div style="margin: 24px">
    <a-table :columns="columns" :dataSource="dataSource" :components="components">
      <template v-slot:action>
        <a href="javascript:;" class="drag-handle" style="cursor: move;">拖动</a>
      </template>
    </a-table>
  </div>
</template>

<script>
const CustomWrapper = ()=> import('./components/CustomWrapper.vue');
const columns = [
  {
    title: "id",
    dataIndex: "id",
    sorter: true,
    width: "20%",
    scopedSlots: { customRender: "name" },
  },
  {
    title: "Gender",
    dataIndex: "gender",
    filters: [
      { text: "Male", value: "male" },
      { text: "Female", value: "female" },
    ],
    width: "20%",
  },
  {
    title: "Email",
    dataIndex: "email",
  },
  {
    title: 'Action',
    key: 'action',
    scopedSlots: { customRender: 'action' },
  },
];

export default {
  name: "App",
  provide() {
    return {
      data: this,
    };
  },
  data() {
    return {
      columns,
      components: {
        body: {
          wrapper: CustomWrapper,
        },
      },
      dataSource: [{
        id:1,
        key: 0,
        date: '2018-02-11',
        amount: 120,
        type: 'income',
        note: 'transfer',
      },
      {
        id:2,
        key: 1,
        date: '2018-03-11',
        amount: 243,
        type: 'income',
        note: 'transfer',
      },
      {
        id:3,
        key: 2,
        date: '2018-04-11',
        amount: 98,
        type: 'income',
        note: 'transfer',
      }],
    };
  },
  mounted(){
  
  },
  methods: {
     listChange(list){
       
     }
  },
};
</script>

<style></style>

CustomWrapper.vue文件

js 复制代码
<template>
  <Draggable ghostClass="ghost" tag="tbody" v-model="data.dataSource" @change="onChange" handle=".drag-handle">
    <slot></slot>
  </Draggable>
</template>
<script>
import Draggable from "vuedraggable";

export default {
  name: 'CustomWrapper',
  components: {
    Draggable
  },
  inject: ["data"],
  data() {
    return {
      
    };
  },
  mounted() {
  
  },
  methods: {
    onChange(evt) {
      this.data.listChange(this.data.dataSource)
    }
  }

};
</script>

文章来源:章鱼
http://114.55.234.134/article/6707a6da9a143e8ffe896fb4

相关推荐
AINative软件工程5 分钟前
编程
前端·llm
晴天167 分钟前
peerDependencies 全面解析:前端依赖生态的核心机制与实战指南
前端·npm
I'mChloe7 分钟前
群晖部署 image-matting:把人像去背景做成一个随开随用的 Web 工具
android·前端
程序员蜡笔熊12 分钟前
Vite 8 换芯实测:Rolldown 替掉双引擎,构建快 3.19 倍
前端·javascript·vue
右耳朵猫AI18 分钟前
Web前端周刊2026W36 | pnpm 12 Rust 重写、Remix 3 RC、Node.js 26.8.0、htmx 4.0 大版本
前端·rust·node.js
平头哥~34 分钟前
Day 21 | animation 与 keyframes:把动画从 A 到 B 变成多点编排
前端·css·css3·css学习
宿67410 小时前
vue3-包管理器
前端·vue.js
@PHARAOH10 小时前
WHAT - Remix 入门和基本实践:理解两套产物
前端·remix
mayaairi11 小时前
Vue2 生命周期完全指南:从创建到销毁的8个钩子函数
前端·javascript·vue.js
研☆香11 小时前
一个简单的气泡弹窗制作
javascript