• vue3拖拽排序 使用 vuedraggable


    vue.draggable.next vue3 拖拽排序

    vue.draggable.next

    下载

    pnpm add vuedraggable@next
    
    • 1

    使用

    <script lang="ts" setup>
    import { reactive } from "vue";
    import draggable from "vuedraggable";
    
    const list = reactive([
    	{
    		id: 1,
    		name: "zs",
    	},
    	{
    		id: 2,
    		name: "ls",
    	},
    	{
    		id: 3,
    		name: "xr",
    	},
    ]);
    </script>
    
    <template>
    	<draggable :list="list" item-key="id">
    		<template #item="{ element }">
    			<div>{{ element.name }}</div>
    		</template>
    	</draggable>
    </template>
    
    <style lang="scss" scoped></style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    slot 其他插槽

    Header/Footer

    可用作图片上传的按钮,保持在同一行

    <template>
    	<draggable :list="list" item-key="id">
          <template #header>
             <button>Add</button>
          </template>
    
    		<template #item="{ element }">
    			<div>{{ element.name }}</div>
    		</template>
    
          <template #Footer>
             <button>Add</button>
          </template>
    	</draggable>
    </template>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    handle 手柄,指定某一元素可拖拽

    <template>
    	<draggable :list="myArray" item-key="id" handle=".handle">
    		<template #item="{ element, index }">
    			<div>
    				<span class="handle">点我拖动</span>
    				<span class="px-20px">{{ element.name }}</span>
    				<span @click="handleDelete(index)">X</span>
    			</div>
    		</template>
    	</draggable>
    </template>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    animation 拖拽动画时长

    <template>
    	<draggable :list="myArray" item-key="id" :animation="2000">
    		<template #item="{ element }">
    			<div>{{ element.name }}</div>
    		</template>
    	</draggable>
    </template>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    change 事件

    <script lang="ts" setup>
    import { reactive } from "vue";
    import draggable from "vuedraggable";
    interface List {
    	id: number;
    	name: string;
    }
    const list: List[] = reactive([
    	{
    		id: 1,
    		name: "zs",
    	},
    	{
    		id: 2,
    		name: "ls",
    	},
    	{
    		id: 3,
    		name: "xr",
    	},
    ]);
    
    function onChange(e: { moved: { element: List; newIndex: number; oldIndex: number } }) {
    	console.log("拖拽元素", e.moved.element);
    	console.log("拖拽元素后索引", e.moved.newIndex);
    	console.log("拖拽元素前索引", e.moved.oldIndex);
    }
    </script>
    
    <template>
    	<draggable :list="list" item-key="id" @change="onChange">
    		<template #item="{ element }">
    			<div>{{ element.name }}</div>
    		</template>
    	</draggable>
    </template>
    
    <style lang="scss" scoped></style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
  • 相关阅读:
    系列十一、阻塞队列
    M代码管理篇
    第七章《Java的异常处理》第2节:异常的分类及处理方法
    B/S 架构 与 C/S 架构
    【面试题精讲】接口和抽象类有什么共同点和区别?
    基于 yolov5n6 和tkinker实现的检测模型的可视化界面
    MATLB|改进的前推回代法求解低压配电网潮流
    树莓派通过网线连接电脑(校园网也能连接),实现SSH连接
    H4TCPE;H4ETTC;四[4-(4‘-羧基苯基)苯基]乙烯;AIE聚集诱导发光材料
    8. SAP ABAP OData 服务如何支持创建(Create)操作
  • 原文地址:https://blog.csdn.net/weixin_43512977/article/details/134538522