安装:

npm install --save vue-draggable-resizable

我的目录结构:

引用:

import vdr from "vue-draggable-resizable";
import "vue-draggable-resizable/dist/VueDraggableResizable.css";

使用:


我的index.vue

<template><div class="home content"><el-button-groupclass="animate__animated animate__backInDown edit-layout-btns"v-show="$store.state.editLayout"><el-buttontype="primary"size="mini"icon="el-icon-check"@click="okLayout">确认调整</el-button><el-button size="mini" icon="el-icon-close" @click="closeLayout">关闭调整</el-button></el-button-group><template v-for="(card, index) in myCards"><vdr:key="index":w="card.w":h="card.h":x="card.x":y="card.y":class-name="$store.state.editLayout ? 'vdr-body-action' : 'vdr-body'":min-width="vdrConfig.minWidth":enable-native-drag="true":draggable="$store.state.editLayout":resizable="$store.state.editLayout"@activated="changeCardItem(card)"@resizestop="onResizstop"@dragstop="onDragstop"><div class="panel-body"><el-dropdownv-show="$store.state.editLayout"size="small"@command="settings($event, card, index)"class="handle-btns"><el-button plain type="primary" size="mini">操作</el-button><el-dropdown-menu slot="dropdown"><el-dropdown-item command="1">删除</el-dropdown-item><!-- <el-dropdown-item command="2">全部</el-dropdown-item> --></el-dropdown-menu></el-dropdown><el-card:body-style="{height: card.h - 39 + 'px',overflow: 'auto',padding: 0,}"><div slot="header"><h4 class="title" @click="$router.push(card.url)" style="">{{ card.name }}</h4></div><component :is="card.component" :ref="card.component" /></el-card></div></vdr></template><el-dialogtitle="添加面板"width="500px"append-to-body:visible="$store.state.addLayout":before-close="closeAddPanel"><el-form :model="addPanelForm"><el-form-item><el-selectmultiplefilterablev-model="addPanelForm.components"placeholder="请选组件"><template v-for="(cmp, index) in components"><el-option:key="index":label="cmp.name":value="cmp.component"/></template></el-select></el-form-item></el-form><div slot="footer" class="dialog-footer"><el-button @click="closeAddPanel">取 消</el-button><el-button type="primary" @click="okAddPanel()">确 定</el-button></div></el-dialog></div>
</template><script>
/*** @author        全易* @time          2021-01-11 11:12:22  星期一* @description   首页*/
import vdr from "vue-draggable-resizable";
import "vue-draggable-resizable/dist/VueDraggableResizable.css";
import NewUsers from "./panels/new-users";
import Withdraw from "./panels/withdraw";
import Refunds from "./panels/refund";
import Orders from "./panels/orders";
import api from "@/service/api";export default {name: "Home",components: {vdr,NewUsers,Withdraw,Refunds,Orders,},data() {return {allComponent: [{ name: "今日新增用户", component: "NewUsers" },{ name: "用户提现", component: "Withdraw" },{ name: "订单退款", component: "Refunds" },{ name: "未付款订单", component: "Orders" },],vdrConfig: {editActive: false,minWidth: 300,tolerance: 10,changeCard: {},},myCards: [{component: "NewUsers",url: "/management/use-electric",h: 280,id: "1",name: "今日新增用户",w: 450,x: 5,y: 4,},{component: "Withdraw",url: "/settlement/withdraw",h: 280,id: "2",name: "用户提现",w: 631,x: 472,y: -278,},{component: "Refunds",url: "/settlement/refund",h: 280,id: "3",name: "订单退款",w: 565,x: 1119,y: -560,},{component: "Orders",url: "/orders/order-manage",h: 400,id: "4",name: "未付款订单",w: 1678,x: 5,y: -543,},],addPanelForm: {components: [],},};},created() {console.log(this.$store.state.userInfo.roleGroup);this.hasLayout();},computed: {// 添加组件下拉选去重components() {return this.myCards.filter((component) => {return this.myCards.every((card) => {return card.component !== component.component;});});},},methods: {// 布局记忆hasLayout() {api.homeLayout().then((res) => {console.log(res);if (res.code === 0 && res.data.length !== 0) {this.myCards = JSON.parse(res.data[0].homeJson);}});},// 选中要调整的面板时changeCardItem(panel) {if (this.$store.state.editLayout) {console.log(panel);this.vdrConfig.changeCard = panel;}},// 停止改变面板尺寸时onResizstop(x, y, width, height) {console.log(`调整id${this.vdrConfig.changeCard.id}面板,宽:${width},高:${height},X:${x},Y:${y}`);this.myCards.filter((card) => {if (this.vdrConfig.changeCard.id === card.id) {card.w = width;card.h = height;card.x = x;card.y = y;}return true;});},// 停止移动面板时onDragstop(x, y) {console.log(`调整第${this.vdrConfig.changeCard.id}个,X:${x},Y:${y}`);this.myCards.map((card) => {if (this.vdrConfig.changeCard.id === card.id) {console.log(card);card.x = x;card.y = y;}});},// 删除面板detelePanel(obj, index) {this.myCards.splice(index, 1);},// 设置面板settings(command, card, index) {// console.log(command, card, index);switch (command) {case "1":this.detelePanel(card, index);break;case "2":break;}},// 确定调整布局okLayout() {this.$store.commit("editLayout", false);api.editHomeLayout({homeJson: JSON.stringify(this.myCards),}).then((res) => {if (res.code === 0) {this.$message.success("调整成功");this.hasLayout();}});},// 关闭调整布局closeLayout() {this.$store.commit("editLayout", false);this.hasLayout();},// 关闭添加展示面板closeAddPanel(done) {// @param done is a functionthis.$store.commit("addLayout", false);this.addPanelForm.components = [];},// 确定添加功能面板okAddPanel() {console.log(this.addPanelForm);if (this.addPanelForm.components.length < 1) {this.$message.warning("请选择组件");return false;}},},// 路由离开前beforeRouteLeave(to, from, next) {// 可以访问组件实例 `this`// console.log(to, from);if (this.$store.state.editLayout) {this.$confirm("您在调整布局", "提示", {confirmButtonText: "保存配置并离开",cancelButtonText: "继续调整",type: "warning",}).then(() => {this.okLayout();next();}).catch(() => {});} else {next();}},
};
</script><style lang="less" scoped>
.edit-layout-btns {position: fixed;top: 0;right: 100px;z-index: 99999;
}
.vdr-body {border: 1px dashed transparent;
}
.vdr-body-action {border: 1px dashed #b4b4b4;z-index: 9999999 !important;
}
.panel-body {.handle-btns {position: absolute;top: 0;right: 0;}/deep/.el-card__header {padding: 8px;border-bottom: none;.title {cursor: pointer;display: inline-block;&:hover {color: #19aa8d;}}}
}
</style>

使用文档:https://github.com/mauricius/vue-draggable-resizable

vue-draggable-resizable 自定义多组件的拖动、缩放功能相关推荐

  1. vue.draggable 拖拽 ant 组件布局

    vue.draggable 拖拽 项目需求中,需要支持拖拽,即找到了vue.draggable,下面来说一下基本使用方法 1.首先需要安装它,官网地址 https://www.itxst.com/vu ...

  2. 基于 springboot + vue 的 element-ui 的 upload 组件头像上传功能

    基于 springboot + vue 的 element-ui 的 upload 组件头像上传 为了方便我们自己本地测试使用,我们将文件上传至自己电脑的磁盘中,由于项目是前后端分离的,所以我们会直接 ...

  3. vue 模仿机票自定义日历组件,区间选择

    1.创建组件  components > calander > index.vue <template><div class="page" v-if= ...

  4. vuejs滚动条_Vue.js桌面端自定义滚动条组件之美化滚动条VScroll

    前言 前段时间有给大家分享一个vue桌面端弹框组件,今天再分享最近开发的一个vue pc端自定义滚动条组件. vscroll 一款基于vue2.x开发的网页端轻量级超小巧自定义美化滚动条组件.支持是否 ...

  5. vue学习笔记-03-浅谈组件-概念,入门,如何用props给组件传值?

    vue学习笔记-03-浅谈组件-概念,入门,如何用props给组件传值? 文章目录 vue学习笔记-03-浅谈组件-概念,入门,如何用props给组件传值? 什么是组件? 为什么要使用组件? 如何使用 ...

  6. Vue.Draggable 实现组件拖拽

    Vue.Draggable 实现组件拖拽 特性 支持触摸设备 支持拖拽和选择文本 支持智能滚动 支持不同列表之间的拖拽 不以jQuery为基础 和视图模型同步刷新 和vue2的国度动画兼容 支持撤销操 ...

  7. vue+elementUI实现自定义表单模板组件(一)

    前言 如下图,实现一个可以自定义的表单.本文以实现思路为主,并未提供完整代码. 思路 1.页面布局为左中右布局:左边显示可以定义的表单控件,中间显示预览效果,右边则为选中某个控件后可以编辑的属性.如下 ...

  8. VUE 拖拽组件 vue.draggable

    中文文档 https://www.itxst.com/vue-draggable/tutorial.html 安装 npm i -S vuedraggable 属性 属性名称 说明 group :gr ...

  9. vue组件的拖动排序

    Vue Grid Layout -适用Vue.js的栅格布局系统 01 - 基本 | Vue Grid Layout -️ 适用Vue.js的栅格布局系统 (jbaysolutions.github. ...

最新文章

  1. fatal: Unsupported SSL backend ‘“openssl”‘. Supported SSL backends:
  2. 注意稳住或慢抬离合,给车辆一些缓冲,才能平顺起步。抬得太快,
  3. tf keras Dense源码解析
  4. Python+Hive环境搭建
  5. 使用JPA和@NamedQueries的Spring数据
  6. 阿里给所有卖家发福利:全球首个人工智能中文字库免费用
  7. 面向服务的架构SOA
  8. 【汇编语言与计算机系统结构笔记11】程序格式与伪操作:段定义、堆栈 #简洁笔记形式
  9. 机器学习工程师 - Udacity 强化学习 Part Eleven
  10. 常用测试工具-----IPOP
  11. ActivityManager Displayed 源码位置
  12. java前后端分离,前端部署的方式
  13. elememt ui 组件 dialog使用备忘
  14. Arduino 使用 LCD1602 显示屏IIC驱动
  15. 电能计量芯片HLW8110/HLW8112
  16. 面试官:为啥需要枚举?枚举有什么作用?怎么用枚举实现单例?
  17. fckeditor文档库
  18. 图片也查重?期刊用AI审论文防造假,旋转/翻转/拉伸都不行
  19. 物体6D位姿估计方法总结
  20. 2019年英语专升本英语阅读「Part II 阅读专区」【文章(图片)、答案、词汇记忆】

热门文章

  1. 推荐三款强大的有3D效果的js图表库
  2. java中判断字符串是否为汉字或其他字符
  3. Hive常见查询操作与函数汇总
  4. F 大吉大利,今晚吃鸡----跑毒篇
  5. 机器学习中的惩罚线性回归模型应用(two)
  6. 程序员每天都在使用的6个惊讶的软技能
  7. [附源码]JAVA+ssm化妆品销售购物系统(程序+Lw)
  8. GitHub的下载、安装与使用
  9. 【阿冈感动】月最圆时写给乔月光的歌《爱是温暖的月光》
  10. TI SAE J1772兼容电动汽车充电器参考设计TIDA-010071