vuedraggable拖拽生成页面---简单Demo
2022/5/30 23:22:37
本文主要是介绍vuedraggable拖拽生成页面---简单Demo,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>vuedrag</title> <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.min.js"></script> <script src="http://www.itxst.com/package/sortable/Sortable.min.js"></script> <script src="http://www.itxst.com/package/vuedraggable/vuedraggable.umd.min.js"></script> <style> #app { display: flex; justify-content: space-around; } .li2, .li { background-color: powderblue; width: 100px; margin: 10px auto; padding: 20px; position: relative; } .li2 { background-color: pink; } .right { width: 200px; /* 保证list2没有内容时仍然可拖拽左边模块内容 */ min-height: 500px; background-color: #eee; } .delbtn { width: 24px; position: absolute; right: 0; top: 0; font-size: 12px; line-height: 24px; cursor: pointer; } </style> </head> <body> <div id="app"> <!-- 左侧菜单区 --> <draggable v-model="list1" draggable=".li" v-bind="dragOptions" :options="{sort: false, group: {name: 'field', pull:'clone',put: false}}"> <div v-for="d in list1" :key="d.id" class="li" :class="{'disabled':d.disabled}">{{d.name}}</div> </draggable> <!-- 右侧页面生成去 --> <draggable class="right" group="field" v-bind="dragOptions" :list="list2" @change="toChange"> <div v-for="(d,index) in list2" :key="'r'+index" class="li2"> <span>{{d.name}}</span> <div class="delbtn" @click="del(index)">删除</div> </div> </draggable> </div> <script> var vm = new Vue({ el: "#app", data: { dragOptions: { animation: 500, filter: '.disabled' //class为disabled时不可拖拽 }, list1: [ // 重复拖动相同元素时key重复,需要处理 { name: "头部", id: 1, disabled: true }, //设置第一项不可拖动 { name: "标题", id: 2 }, { name: "图片", id: 3 }, { name: "分割线", id: 4 } ], list2: [] }, methods: { toChange(e) { console.log(e) if (e.added) { console.log(this.list2) } }, del(idx) { this.list2.splice(idx, 1) } } }) </script> </body> </html>
复制到空的html直接查看效果
效果演示
这篇关于vuedraggable拖拽生成页面---简单Demo的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-26React入门教程:从零开始搭建你的第一个React应用
- 2024-12-25Vue2入门教程:轻松掌握前端开发基础
- 2024-12-25Vue3入门指南:快速搭建你的第一个Vue3项目
- 2024-12-25JS基础知识入门教程
- 2024-12-25React基础知识详解:从入门到初级应用
- 2024-12-25Vue3基础知识详解与实战指南
- 2024-12-25Vue3学习:从入门到初步掌握
- 2024-12-25Vue3入门:新手必读的简单教程
- 2024-12-23【JS逆向百例】爱疯官网登录逆向分析
- 2024-12-21Vue3教程:新手入门到实践应用