雖然之前適配過舊版組件,但是因為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 style="height: 500px; width: 500px; border: 1px solid red; position: relative;"> <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 draggable resizable 實現可拖拽縮放的組件功能 ,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com