2.0.1 • Published 8 months ago

vue-drag-level v2.0.1

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

vue-drag-level

npm npm vue3

Vue3 component that simulates a user typing, selecting, and erasing text.

Checkout the offical project here.

Table of contents

效果

下图中你不喜欢的图标皆提供插槽以供自定义

1、第一层拖拽为组 npm.io

2、树形拖拽 npm.io

Installation

npm install --save vue-drag-level

Global import

Install the component:

import { createApp } from 'vue' 
import vueDragLevel from "vue-drag-level";
import "vue-drag-level/dist/style.css"; 
import App from './App.vue' 

const app = createApp(App) 
app.use(vueDragLevel) 
app.mount('#app')

Manual import

<template>
  <div>
    <dragLevel
      groupDrag
      treeDrag
      :data="departResultStrings"
      :no-drag-class="['itemDisabled']"
      @onDragEnd="onDragEnd"
    >
      <template #default="{ item }">
        <div
          :class="{
            itemBox: true,
            itemDisabled: item.id == 1,
          }"
        >
          <span>{{ item.name }}</span>
        </div>
      </template>
    </dragLevel>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import dragLevel from "./components/index.vue";

const departResultStrings = ref([
  {
    id: 1,
    name: "row1",
  },
  {
    id: 3,
    name: "row3",
  },
  {
    id: 2,
    name: "row2",
  },
  {
    id: 4,
    name: "row4",
  },
  {
    id: 5,
    name: "row5",
  },
  {
    id: 6,
    name: "row6",
  },
  {
    id: 7,
    name: "row7",
  },
]);

function onDragEnd(res: any) {
  console.log(res);
}
</script>

<style scoped>
.itemBox {
  padding: 5px 10px;
  border-bottom: 1px solid #ccc;
}
</style>

Properties

你可以使用以下属性:

参数类型默认值说明
dataArray[]显示的数据
idStringid唯一id-key
noDragClassArray[]禁止拖拽的class元素
treeDragBooleanfalse允许树形拖拽,拖拽时,虚线左边是同级,虚线右边是子级
levelGapString30px树形中,不同层级的间隔
groupDragBooleanfalse允许第一级拖拽成组
groupKeyStringparentId唯一父级key
groupListKeyStringchildren唯一子级List-key
showGroupTagLineBooleantrue是否显示不同组之间的分隔标识线
groupDragHoverBooleantrue组拖拽按钮鼠标浮动出现,默认true,为false将一存直在
levelByTopBooleanfalse组项离开组时回到最外层数组或者父层所在数组,默认回到父层所在数组
showDelBtnBooleantrue是否展示删除按钮
beforeDeletefunction(res)true删除之前的钩子,参数为删除的数据,若定义该函数,则必须返回 true 或者返回 Promise 且被 resove,才会执行删除;返回其他均不执行删除

Events

你能使用以下事件:

事件名称DescriptionUsage
onDragEnd每次操作数据的回调@onDragEnd="doSomeThing()"
delItem点击删除的数据回调@delItem="doSomeThing()"

Slots

你能使用以下插槽:

插槽名称说明
default自定义列的内容,参数为 {item}
joinGroup加入组的样式内容
levelGroup离开组的样式内容
groupDrag拖拽组的样式内容
delete删除的样式内容

Features

  • 树形拖拽操作的交互优化,比如出现两个按钮替换虚线的左右
  • 组拖拽为单行数据的子级

License

MIT