這篇文章將為大家詳細講解有關vue中draggable resizable如何實現可拖拽縮放的組件功能,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
雖然之前適配過舊版組件,但是因為2.0版本原作者對代碼進行了重構,原來修改的代碼照搬是不可能的了。
所以也就一直沒有將 沖突檢測 以及 吸附對齊 功能適配到2.0版本,最近正好有時間就適配一下。
新增特征
沖突檢測
吸附對齊
默認樣式優化
功能預覽

項目地址
github.com/gorkys/vue-…
如果喜歡該項目,歡迎 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
當調用 snap 時,定義組件與元素之間的對齊距離,以像素(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'
// 導入默認樣式
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是一款友好的、多用途且高性能的JavaScript框架,使用vue可以創建可維護性和可測試性更強的代碼庫,Vue允許可以將一個網頁分割成可復用的組件,每個組件都包含屬于自己的HTML、CSS、JavaScript,以用來渲染網頁中相應的地方,所以越來越多的前端開發者使用vue。
關于“vue中draggable resizable如何實現可拖拽縮放的組件功能”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。