溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

vue中draggable resizable如何實(shí)現(xiàn)可拖拽縮放的組件功能

發(fā)布時(shí)間:2021-05-21 10:09:55 來源:億速云 閱讀:1558 作者:小新 欄目:web開發(fā)

這篇文章將為大家詳細(xì)講解有關(guān)vue中draggable resizable如何實(shí)現(xiàn)可拖拽縮放的組件功能,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

雖然之前適配過舊版組件,但是因?yàn)?.0版本原作者對代碼進(jìn)行了重構(gòu),原來修改的代碼照搬是不可能的了。

所以也就一直沒有將 沖突檢測 以及 吸附對齊 功能適配到2.0版本,最近正好有時(shí)間就適配一下。

新增特征

  • 沖突檢測

  • 吸附對齊

  • 默認(rèn)樣式優(yōu)化


功能預(yù)覽

vue中draggable resizable如何實(shí)現(xiàn)可拖拽縮放的組件功能

項(xiàng)目地址

github.com/gorkys/vue-…

如果喜歡該項(xiàng)目,歡迎 Star

新增Props

isConflictCheck

Type: Boolean

Required: false

Default: false

定義組件是否開啟沖突檢測。

<vue-draggable-resizable :is-conflict-check="true">

snap

Type: Boolean

Required: false

Default: false

定義組件是否開啟元素對齊。

<vue-draggable-resizable :snap="true">

snapTolerance

Type: Number

Required: false

Default: 5

當(dāng)調(diào)用 snap 時(shí),定義組件與元素之間的對齊距離,以像素(px)為單位。

<vue-draggable-resizable :snap="true" :snap-tolerance="20">

其它屬性請參考 vue-draggable-resizable 官方文檔

安裝使用

$ npm install --save vue-draggable-resizable-gorkys

全局注冊組件

//main.js
import Vue from 'vue'
import vdr from 'vue-draggable-resizable-gorkys'

// 導(dǎo)入默認(rèn)樣式
import 'vue-draggable-resizable-gorkys/dist/VueDraggableResizable.css'
Vue.component('vdr', vdr)

局部注冊組件

<template>
 <div >
  <vdr :w="100" :h="100" v-on:dragging="onDrag" v-on:resizing="onResize" :parent="true">
   <p>Hello! I'm a flexible component. You can drag me around and you can resize me.<br>
   X: {{ x }} / Y: {{ y }} - Width: {{ width }} / Height: {{ height }}</p>
  </vdr>
  <vdr
   :w="200"
   :h="200"
   :parent="true"
   :debug="false"
   :min-width="200"
   :min-height="200"
   :isConflictCheck="true"
   :snap="true"
   :snapTolerance="20"
  >
  </vdr>
 </div>
</template>

<script>
import vdr from 'vue-draggable-resizable-gorkys'
import 'vue-draggable-resizable-gorkys/dist/VueDraggableResizable.css'
export default {
 components: {vdr},
 data: function () {
  return {
   width: 0,
   height: 0,
   x: 0,
   y: 0
  }
 },
 methods: {
  onResize: function (x, y, width, height) {
   this.x = x
   this.y = y
   this.width = width
   this.height = height
  },
  onDrag: function (x, y) {
   this.x = x
   this.y = y
  }
 }
}
</script>

為什么要使用Vue

Vue是一款友好的、多用途且高性能的JavaScript框架,使用vue可以創(chuàng)建可維護(hù)性和可測試性更強(qiáng)的代碼庫,Vue允許可以將一個(gè)網(wǎng)頁分割成可復(fù)用的組件,每個(gè)組件都包含屬于自己的HTML、CSS、JavaScript,以用來渲染網(wǎng)頁中相應(yīng)的地方,所以越來越多的前端開發(fā)者使用vue。

關(guān)于“vue中draggable resizable如何實(shí)現(xiàn)可拖拽縮放的組件功能”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯(cuò),請把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI