Vue中使用vue-drag-resize实现窗体可拖拽和随意缩放大小

这篇具有很好参考价值的文章主要介绍了Vue中使用vue-drag-resize实现窗体可拖拽和随意缩放大小。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

场景

若依前后端分离版手把手教你本地搭建环境并运行项目:

若依前后端分离版手把手教你本地搭建环境并运行项目_ruoyi本地调式_霸道流氓气质的博客-CSDN博客

在上面的基础上,实现弹窗窗体可移动以及随意缩放大小。

效果如下

Vue中使用vue-drag-resize实现窗体可拖拽和随意缩放大小,Vue,vue.js,前端,javascript 

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi 

实现

1、vue-drag-resize

https://github.com/kirillmurashov/vue-drag-resize

示例demo地址

Vue-drag-resize

2、安装

npm i -s vue-drag-resize

3、注册组件

import Vue from 'vue'
import VueDragResize from 'vue-drag-resize'

Vue.component('vue-drag-resize', VueDragResize)

4、组件使用

<template>
    <div id="app">
        <VueDragResize :isActive="true" :w="200" :h="200" v-on:resizing="resize" v-on:dragging="resize">
            <h3>Hello World!</h3>
            <p>{{ top }} х {{ left }} </p>
            <p>{{ width }} х {{ height }}</p>
        </VueDragResize>
    </div>
</template>

<script>
    import VueDragResize from 'vue-drag-resize';

    export default {
        name: 'app',

        components: {
            VueDragResize
        },

        data() {
            return {
                width: 0,
                height: 0,
                top: 0,
                left: 0
            }
        },

        methods: {
            resize(newRect) {
                this.width = newRect.width;
                this.height = newRect.height;
                this.top = newRect.top;
                this.left = newRect.left;
            }
        }
    }
</script>

5、属性

isActive

Type: Boolean
Required: false
Default: false

Determines whether the component should be active.

确定组件是否应处于活动状态。

<vue-drag-resize :isActive="true">
preventActiveBehavior

Type: Boolean
Required: false
Default: false

Disable behavior of the component by clicking on it and clicking outside the component's area (isActive: true / false).
If the prop is enabled, the component is oriented only to the specified.

通过单击组件并单击组件区域外部来禁用组件的行为(isActive:true / false)。
如果启用了prop,则组件仅面向指定的。

<vue-drag-resize :preventActiveBehavior="true">
parentW

Type: Number
Required: false
Default: 0

Define the initial width of the parent element. If not specified it calculated automatically.
With this parameter, you can set the bounding area for the component, and also it is used when resizing in real time.

定义父元素的初始宽度。 如果未指定,则自动计算。
使用此参数,您可以设置组件的边界区域,并在实时调整大小时使用它。

<vue-drag-resize :parentW="2000">
parentH

Type: Number
Required: false
Default: 0

Define the initial height of the parent element. If not specified it calculated automatically.
With this parameter, you can set the bounding area for the component, and also it is used when resizing in real time.

定义父元素的初始高度。 如果未指定,则自动计算。 使用此参数,您可以设置组件的边界区域,并在实时调整大小时使用它。

<vue-drag-resize :parentH="2000">
parentScaleX

Type: Number
Required: false
Default: 1

Define the initial horizontal scale or the parent element. Same value in parent's transform: scale() css definition.
The drag/resize and the sticks' sizes will computed with this value.

定义初始水平比例或父元素。父级的transform:scale()css定义中的值相同。
拖动/调整大小和杆的大小将使用该值计算。

<vue-drag-resize :parentScaleX="0.5">
parentScaleY

Type: Number
Required: false
Default: 1

Define the initial vertical scale or the parent element. Same value in parent's transform: scale() css definition.
The drag/resize and the sticks' sizes will computed with this value.

定义初始垂直比例或父元素。父级的transform:scale()css定义中的值相同。
拖动/调整大小和杆的大小将使用该值计算。

<vue-drag-resize :parentScaleY="0.5">
isDraggable

Type: Boolean
Required: false
Default: true

Determines whether the component should draggable.

确定组件是否应可拖动。

<vue-drag-resize :isDraggable="false">
isResizable

Type: Boolean
Required: false
Default: true

Determines whether the component should resize.

确定组件是否应调整大小。

<vue-drag-resize :isResizable="false">
parentLimitation

Type: Boolean
Required: false
Default: false

Limits the scope of the component's change to its parent size.

将组件更改的范围限制为其父大小。

<vue-drag-resize :parentLimitation="true">
snapToGrid

Type: Boolean
Required: false
Default: false

Determines whether the component should move and resize in predefined steps.

<vue-drag-resize :snapToGrid="true">
gridX

Type: Number
Required: false
Default: 50

Define the grid step size for the horizontal axis. Both sides of the component (left and right) will snap to this step.

<vue-drag-resize :snapToGrid="true" :gridX="20">
gridY

Type: Number
Required: false
Default: 50

Define the grid step size for the vertical axis. Both sides of the component (top and bottom) will snap to this step.

<vue-drag-resize :snapToGrid="true" :gridY="20">
aspectRatio

Type: Boolean
Required: false
Default: false

Determines whether the component should retain its proportions.

确定组件是否应保持其比例。

<vue-drag-resize :aspectRatio="false">
w

Type: Number|String
Required: false
Default: 200

Define the initial width of the component.
The value can either be a number >= 0 or the string 'auto'.
If set to 'auto', the initial width value will be equal to the width of the content within the component.

定义组件的初始宽度。

<vue-drag-resize :w="200">
h

Type: Number|String
Required: false
Default: 200

Define the initial height of the component.
The value can either be a number >= 0 or the string 'auto'.
If set to 'auto', the initial height value will be equal to the height of the content within the component.

定义组件的初始高度。

<vue-drag-resize :h="200">
minw

Type: Number
Required: false
Default: 50

Define the minimal width of the component.

定义组件的初始宽度。

<vue-drag-resize :minw="50">
minh

Type: Number
Required: false
Default: 50

Define the minimal height of the component.

定义组件的最小高度。

<vue-drag-resize :minh="50">
x

Type: Number
Required: false
Default: 0

Define the initial x position of the component.

定义组件的初始X位置。

<vue-drag-resize :x="0">
y

Type: Number
Required: false
Default: 0

Define the initial y position of the component.

定义组件的初始Y位置。

<vue-drag-resize :y="0">
z

Type: Number|String
Required: false
Default: auto

Define the zIndex of the component.

定义组件的zindex(层级)。

<vue-drag-resize :z="999">
stickSize

Type: Number
Required: false
Default 8

Define the sticks' size.

<vue-drag-resize :stickSize="12">
sticks

Type: Array
Required: false
Default: ['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml']

Define the array of handles to restrict the element resizing:

定义句柄数组以限制元素大小调整:

  • tl - Top left
  • tm - Top middle
  • tr - Top right
  • mr - Middle right
  • br - Bottom right
  • bm - Bottom middle
  • bl - Bottom left
  • ml - Middle left
<vue-drag-resize :sticks="['tm','bm','ml','mr']">
axis

Type: String
Required: false
Default: both

Define the axis on which the element is draggable. Available values are xyboth or none.

定义元素可拖动的轴。 可用值为xybothnone

<vue-drag-resize axis="x">
dragHandle

Type: String
Required: false

Defines the selector that should be used to drag the component.

定义应该用于拖动组件的选择器。

<vue-drag-resize dragHandle=".drag">
dragCancel

Type: String
Required: false

Defines a selector that should be used to prevent drag initialization.

定义应该用于防止拖动初始化的选择器。

<vue-drag-resize dragCancel=".drag">
contentClass

Type: String
Required: false

Defines a class that is applied on the div with the class vdr

<vue-drag-resize contentClass="box-shaddow">

Events

clicked

Required: false
Parameters: Original event handler

Called whenever the component gets clicked.

单击组件时调用。

<vue-drag-resize @clicked="onActivated">
activated

Required: false
Parameters: -

Called whenever the component gets clicked, in order to show handles.

单击组件时调用,以显示句柄。

<vue-drag-resize @activated="onActivated">
deactivated

Required: false
Parameters: -

Called whenever the user clicks anywhere outside the component, in order to deactivate it.

每当用户单击组件外部的任何位置时调用,以便将其停用。

<vue-drag-resize @deactivated="onDeactivated">
resizing

Required: false
Parameters: object

{
    left: Number, //the X position of the component
    top: Number, //the Y position of the component
    width: Number, //the width of the component
    height: Number //the height of the component
}

Called whenever the component gets resized.

每当组件调整大小时调用。

<vue-drag-resize @resizing="onResizing">
resizestop

Required: false
Parameters: object

{
    left: Number, //the X position of the component
    top: Number, //the Y position of the component
    width: Number, //the width of the component
    height: Number //the height of the component
}

Called whenever the component stops getting resized.

每当组件停止调整大小时调用。

<vue-drag-resize @resizestop="onResizstop">
dragging

Required: false
Parameters: object

{
    left: Number, //the X position of the component
    top: Number, //the Y position of the component
    width: Number, //the width of the component
    height: Number //the height of the component
}

Called whenever the component gets dragged.

每当拖动组件时调用。

<vue-drag-resize @dragging="onDragging">
dragstop

Required: false
Parameters: object

{
    left: Number, //the X position of the component
    top: Number, //the Y position of the component
    width: Number, //the width of the component
    height: Number //the height of the component
}

Called whenever the component stops getting dragged.

每当组件停止拖动时调用。文章来源地址https://www.toymoban.com/news/detail-676888.html

<vue-drag-resize @dragstop="onDragstop">

到了这里,关于Vue中使用vue-drag-resize实现窗体可拖拽和随意缩放大小的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • vue 进度条组件(可拖拽可点击)

    在日常的开发当中,随着项目的需求复杂化,自定义组件也越来越常见,而且扩展性也比一些组件库要更加全面,比如视频播放器的进度条。 可自定义设置以下属性: 当前进度value,默认50 是否可拖拽isDrag,默认true 设置最小值min,默认0 设置最大值max,默认100 进度条颜色

    2024年02月16日
    浏览(26)
  • Vue3封装可拖拽的弹窗

    核心代码(复制就可以使用了) 使用方式

    2024年01月19日
    浏览(32)
  • Qt程序设计-无边框可移动可拖拽调整大小窗体

    本文讲解Qt-无边框可移动可拖拽调整大小窗体。 通过鼠标的按下移动进行窗体的移动,拖拽调整窗体大小。 实现过程如下: 创建QWidget窗体,添加一个按钮控制窗体的关闭。

    2024年02月19日
    浏览(31)
  • 基于vue的可拖拽设计的报表看板设计器

    gitee上的不错项目,基于vue实现的可拖拽的看板设计器可以自由搭配颜色和图标,开发者可以只关注业务数据接口,前端不擅长的人员可以直接轻松上手。 1.可支持的元素 文字,边框,常见图表,柱形图,折线饼图等等,还有一些列表数据,当然还支持iframe嵌套,当组件满足

    2024年02月11日
    浏览(49)
  • 基于vue+Element UI的文件上传(可拖拽上传)

    drag: 支持拖拽上传 action:必选参数,上传的地址 ref:这里主要是用于文件上传完成后清除文件的 on-remove:文件列表移除文件时的钩子 auto-upload:是否在选取文件后立即进行上传 on-change:文件状态改变时的钩子,添加文件、上传成功和上传失败时都会被调用 注:这里使用的

    2023年04月08日
    浏览(33)
  • Vue中 echarts响应式页面变化resize()

    Vue项目中开发数据大屏,使用echarts图表根据不同尺寸的屏幕进行适配 BUG:当页面进行缩放时图表大小没有变化 使用到的方法: resize() 调用echarts中内置的resize函数进行自适应缩放,然后添加监控,页面销毁时删掉,避免不必要内存占用 我们先看一下官方文档怎么说 resize 官

    2024年02月08日
    浏览(26)
  • 前端css + js +vue +element-ui 实现响应式布局,根据浏览器窗体大小自动响应

    我的环境是element-ui vue版的,其他的也可以,主要是css和js的内容 首先在data中定义一个对象 其实就是css的样式,不过放在了js 里面而已 这里css设置了两个属性 一个是transform 这个属性对div标签的缩放作用,当浏览器窗口或者屏幕大小改变时,就调整这个属性的值,来等比缩放

    2024年02月13日
    浏览(46)
  • vue3 监听resize窗口事件,离开页面要销毁窗口事件。

    resize事件: resize事件是改变窗口大小时发生的事件,可以在窗口开启、最大化、最小化、窗口大小改变(如拖拉改变窗口大小、move语句改变窗口大小、改变width或height属性以改变窗口大小)时发生。 1.监听浏览器窗口变化,实时获取该窗口的宽度和高度 2.监听 resize 事件 //优

    2024年02月12日
    浏览(34)
  • vue中动态添加class修改div宽高无法触发addEventListener(“resize“)

    在触发事件动态修改class发现resize没有触发。 具体原因没有找到--------无语 因为不知道什么原因只能替代了,网上说resize消耗很大, MutationObserver与ResizeObserver 更节省性能。

    2024年02月12日
    浏览(31)
  • vue自定义h5video视频播放器进度条组件,可拖拽、跳转、倍速、全屏

    一个进度条组件控制多个视频的播放、进度调整。视频可点击全屏观看,唯一的进度条是某个指定视频的视频信息。 全屏 点击进度条跳转 拖动滑块 在菜鸟教程上有以下几个参数的详细解说,这张图忘记哪里看的了,如有认领可评论我贴链接 倍速 // 倍速 handleChangeSpeed(item)

    2024年02月12日
    浏览(65)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包