vue拖拽辅助线+改变元素大小组件

12 篇文章 0 订阅

vue-dragline

项目根据react-dragline 改写为vue。
github地址:https://github.com/BadMooncc/vue-dragline
支持拖拽辅助线,改变元素大小,元素拖拽功能

演示

屏幕录制2022-04-12 17.56.37

Installation

npm

npm install vue-dragline --save

yarn

yarn add install vue-dragline

全局引入

在入口文件main.js

import Vue from 'vue';
import drag from 'vue-dragline';
import 'vue-dragline/lib/vue-dragline.css';
Vue.use(drag);

Example

<template>
  <draggable-container>
    <draggable-child
      v-for="item in initialChildren"
      :key="item.id"
      :id="item.id"
      :width="item.width"
      :height="item.height"
      @stop="handleStop"
      @start="handleStart"
      @drag="handleDrag"
      @resize="handleResize"
      :default-position="item.position">
      <div
        class="item"
        :style="{
          display: 'flex',
          flexDirection: 'column',
          justifyContent: 'center',
          alignItems: 'center',
          cursor: 'move',
          boxSizing: 'border-box',
          background: item.background,
        }">
        <span>size: {{ item.size }}</span>
        <span>drag me</span>
      </div>
    </draggable-child>
  </draggable-container>
</template>
<script>
import 'vue-dragline/lib/vue-dragline.css';
export default {
    data() {
        return {
            initialChildren: [
                { id: 1, background: '#8ce8df', width: 100, height: 100, position: { x: 100, y: 10 } },
                { id: 2, background: '#8ce8df', width: 100, height: 100, position: { x: 400, y: 106 } },
                { id: 3, background: '#d2aff6', width: 100, height: 100, position: { x: 100, y: 316 } },
                { id: 4, background: '#fee493', width: 100, height: 100, position: { x: 480, y: 376 } },
            ]
        };
    },
    methods: {
        handleResize(e) {
            console.log(e, 'handleResize');
        },
        handleDrag(e) {
            console.log(e);
        },
        handleStop(e) {
            console.log(e, 'handleStop');
        },
        handleStart() {
            console.log('开始');
        },
        handleClick() {
            alert(1);
        }
    }
};
</script>

draggable-child组件 Prop Types

PropertyTypeDefaultDescription
idstring/number-元素唯一值,必填
widthnumber-元素宽度
heightnumber-元素高度
default-positionobject {x,y}-元素元素x,y轴坐标

event事件

resize
改变元素大小时触发,返回元素的当前坐标x,y和宽高wdth,height

stop
元素停止拖拽时触发,返回元素的当前坐标x,y和宽高wdth,height

drag
元素拖拽时触发,返回元素的当前坐标x,y和宽高wdth,height

start
元素被选中时触发,返回元素的当前坐标x,y和宽高wdth,height

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值