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

相关推荐
闲云一鹤2 分钟前
Python 入门(三)- PyAutoGUI 自动化教程
前端·python·黑客
D_C_tyu5 分钟前
HTML | 结合Canvas开发具有智能寻路功能的贪吃蛇小游戏实战详解
javascript·算法·游戏·html·bfs
Jay-r8 分钟前
樱花雨特效 WebGL实现 短视频同款浪漫视觉效果(附源码下载)
开发语言·javascript·ecmascript·编程·webgl·代码·樱花雨
凤山老林8 分钟前
Js如何实现一个抽奖程序
前端·javascript·vue.js
我命由我1234510 分钟前
React - Switch、路由精准匹配与模糊匹配、Redirect
开发语言·前端·javascript·react.js·前端框架·html·ecmascript
陆枫Larry17 分钟前
用 Git 别名(Alias)简化日常操作
前端
阿泽·黑核19 分钟前
Easy Vibe Coding 学习心得(三):前端之美——从设计稿到精美界面
前端·vibe coding·easy vibe
无心水29 分钟前
【时间利器】4、JavaScript时间处理全解:Date/moment/dayjs/Temporal
开发语言·前端·javascript·状态模式·openclaw·date/moment·dayjs/temporal
踩着两条虫34 分钟前
AI 驱动的 Vue3 应用开发平台 深入探究(二十五):API与参考之Renderer API 参考
前端·vue.js·人工智能
踩着两条虫34 分钟前
AI 驱动的 Vue3 应用开发平台 深入探究(二十四):API与参考之Provider API 参考
前端·vue.js·ai编程