Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

enn-draggable-list-vue3

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enn-draggable-list-vue3

enn-draggable-list-vue3

  • 0.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

enn-draggable-list-vue3

拖拽列表组件 for Vue3

借助 vuedraggable 组件实现 https://www.npmjs.com/package/vuedraggable/v/4.1.0

示例

DraggableList 拖拽排序组件
<template>
  <DraggableList :list="list" :selectable="true">
    <template #item="{ item }">
      <DraggableListItem
        :item="item"
        @select="onSelect(item)"
        @delete="onDelete(item)"
      >
        {{ item }}
      </DraggableListItem>
    </template>
  </DraggableList>
</template>

<script>
import { DraggableList, DraggableListItem } from '../index';

export default {
  components: {
    DraggableList,
    DraggableListItem,
  },
  data() {
    return {
      list: [
        {
          id: 1,
          name: 1,
        },
        {
          id: 2,
          name: 2,
        },
        {
          id: 3,
          name: 3,
        },
        {
          id: 4,
          name: 4,
        },
      ],
    };
  },
  methods: {
    onSelect(item) {
      console.log('onSelect', item);
    },
    onDelete(item) {
      this.$confirm('确认删除?', null, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'error',
      })
        .then(() => {
          this.list = this.list.filter((field) => field.id !== item.id);

          this.$message({
            type: 'success',
            message: '已删除',
          });
        })
        .catch(() => {});
    },
  },
};
</script>

<style>
</style>

DraggableTransfer 拖拽穿梭组件
<template>
  <DraggableTransfer :source="list" v-model="data" />
</template>

<script>
import { DraggableTransfer } from 'enn-draggable-list';

export default {
  components: {
    DraggableTransfer,
  },
  data() {
    return {
      list: [
        {
          id: 1,
          name: 1,
        },
        {
          id: 2,
          name: 2,
        },
        {
          id: 3,
          name: 3,
        },
        {
          id: 4,
          name: 4,
        },
      ],
      data: [],
    };
  },
};
</script>

<style>
</style>

API

DraggableList Attributes

参数类型必填默认值说明
listArraytrue拖拽列表的数据
itemKeyString遍历列表项 key 的数据源
selectableBooleanfalse是否开启拖拽触发 select 事件
sortableBooleantrue是否可排序
handleString.draggable-list-item .drag-handle可拖拽的元素
optionsObject{ animation: 200, disabled: false, }拖拽相关设置
groupObject\String拖拽组设置{ put: false, push: false, }
cloneFunction当 clone 选项为 true 时,在源组件上调用函数以克隆元素
listTagString可拖动组件作为包含槽的外部元素创建的元素的 HTML 节点类型
listDataObject将附加信息传递给 listTag 声明的子组件
itemTagString子组件外部元素创建的元素的 HTML 节点类型
itemDataObject\Function将附加信息传递给 itemTag 声明的子组件型
Tips
  • listTag 可拖动组件作为包含槽的外部元素创建的元素的 HTML 节点类型。 也可以将 vue 组件的名称作为元素传递。在这种情况下,draggable 属性将传递给创建组件。 又见 componentData,如果你需要的道具或事件设置为创建的组件。 https://www.npmjs.com/package/vuedraggable#componentdata

  • clone 当 clone 选项为 true 时,在源组件上调用函数以克隆元素。唯一参数是要克隆的 viewModel 元素,返回值是其克隆版本。 默认情况下 vue.draggable 重用 viewModel 元素,所以如果你想克隆或深度克隆它,你必须使用这个钩子。 https://www.npmjs.com/package/vuedraggable#clone

DraggableList Event

事件名称说明回调参数
add拖拽添加事件-
select拖拽选中事件-

DraggableList Slot

名称说明参数
item拖拽项的内容{item}

DraggableListItem Attributes

参数类型必填默认值说明
itemObjecttrue子项的数据
hasControlBoolean是否有控制按钮(拖拽、删除)
activeBoolean是否激活,true 时 class 加上 active

DraggableListItem Event

事件名称说明回调参数
select选中事件-
delete删除事件-

DraggableTransfer Attributes

参数类型必填默认值说明
sourceArray左侧拖拽列表的数据
dataArray右侧拖拽列表的数据,使用 v-model 传入
sourceTitleString
resultTitleString
isCloneBooleantrue数据移动的类型 clone / move

DraggableTransfer Slot

名称说明参数
item拖拽项的内容{item}
sourceItem左侧数据列表拖拽项的内容{item}
resultItem右侧结果列表拖拽项的内容{item}
Tips
  • item slot 的优先级比 sourceItem、resultItem 高

本地调试组件

  • npm run dev

发包

  • lib 为发包后的文件夹

Keywords

FAQs

Package last updated on 19 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc