Skip to content

Commit 3676eb2

Browse files
committed
fix: 吸附动态初始化 (#100)
1 parent 0cae5fb commit 3676eb2

4 files changed

Lines changed: 41 additions & 29 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@es-drager/root",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "A draggable, resizable, rotatable component based on vue3",
55
"keywords": [
66
"drag",
Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,44 @@
11
<template>
2-
<Drager
3-
type="text"
4-
v-bind="dragData"
5-
rotatable
6-
boundary
7-
@resize="handleResize"
8-
>
9-
<div :contenteditable="true" style="text-align: center;width: 100%;">啦啦啦啦啦啦啦啦</div>
10-
</Drager>
11-
12-
<Drager type="image" :width="200" :height="120" :left="200" :top="200" rotatable>
13-
<img class="img" style="width: 100%; height: 100%" :src="imgUrl" />
14-
</Drager>
2+
<button @click="snap = !snap">切换snap</button>
3+
<button @click="add">添加</button>
4+
<div style="position: relative;width: 500px;height: 500px;background-color: #ccc;">
5+
<Drager v-for="item in list" :key="item.left + item.top" :width="item.width" :height="item.height" :left="item.left" :top="item.top" :snap="snap" :markline="snap">
6+
</Drager>
7+
</div>
158

169
</template>
1710

1811
<script setup lang="ts">
1912
import { ref } from 'vue'
20-
import imgUrl from '../assets/demo.png'
2113
import Drager from 'es-drager/index'
14+
const snap = ref(false)
15+
const list = ref([
16+
{
17+
width: 100,
18+
height: 100,
19+
left: 100,
20+
top: 100,
21+
},
22+
{
23+
width: 100,
24+
height: 100,
25+
left: 200,
26+
top: 200,
27+
}
28+
])
2229
23-
const textRef = ref<HTMLElement>()
24-
const dragData = ref<any>({
25-
left: 100,
26-
top: 100,
27-
})
28-
29-
function handleResize(_: any, resizeType: string) {
30-
// if (resizeType && !resizeType.includes('-')) {
31-
// const style = window.getComputedStyle(textRef.value!)
32-
// dragData.value.height = parseInt(style.height)
33-
// }
30+
function add() {
31+
list.value.push({
32+
width: 100,
33+
height: 100,
34+
left: 200,
35+
top: 200,
36+
})
3437
}
35-
3638
</script>
39+
40+
<style>
41+
.es-drager-dot {
42+
z-index: 100;
43+
}
44+
</style>

packages/drager/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "es-drager",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "A draggable, resizable, rotatable component based on vue3",
55
"keywords": [
66
"drag",

packages/drager/src/hooks/use-markline.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export function useMarkline(
2727
const update = (marklineData: MarklineData = {}) => {
2828
if (!props.markline) return
2929

30+
if (!lineX || !lineY) { // 初始化markline
31+
init()
32+
}
33+
3034
if (isFn(props.markline)) {
3135
return props.markline(marklineData)
3236
}
@@ -130,7 +134,7 @@ export function useMarkline(
130134
onMounted(() => {
131135
init()
132136
})
133-
137+
134138
return {
135139
marklineEmit
136140
}

0 commit comments

Comments
 (0)