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

相关推荐
EndingCoder2 分钟前
函数基础:参数和返回类型
linux·前端·ubuntu·typescript
码客前端8 分钟前
理解 Flex 布局中的 flex:1 与 min-width: 0 问题
前端·css·css3
Komorebi゛8 分钟前
【CSS】圆锥渐变流光效果边框样式实现
前端·css
工藤学编程21 分钟前
零基础学AI大模型之CoT思维链和ReAct推理行动
前端·人工智能·react.js
徐同保21 分钟前
上传文件,在前端用 pdf.js 提取 上传的pdf文件中的图片
前端·javascript·pdf
怕浪猫22 分钟前
React从入门到出门第四章 组件通讯与全局状态管理
前端·javascript·react.js
博主花神23 分钟前
【React】扩展知识点
javascript·react.js·ecmascript
内存不泄露28 分钟前
基于Spring Boot和Vue 3的智能心理健康咨询平台设计与实现
vue.js·spring boot·后端
欧阳天风30 分钟前
用setTimeout代替setInterval
开发语言·前端·javascript
EndingCoder34 分钟前
箭头函数和 this 绑定
linux·前端·javascript·typescript