Skip to content

Commit

Permalink
vueUse draggable
Browse files Browse the repository at this point in the history
  • Loading branch information
wudengyao committed Aug 10, 2023
1 parent 83c6861 commit 6ccaaac
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/mock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,14 @@ export default [
"url": "/elements/useDraggable"

},
{
"id": "5-1-2",
"name": "useDropZone",
"parent_id": "3",
"type": "2",
"url": "/elements/useDropZone"

},

]
},
Expand Down
6 changes: 6 additions & 0 deletions src/router/modules/vueUse.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export default {
name: 'useDraggable',
meta: {title: 'useDraggable', icon: 'star'}
},
{
path: '/elements/useDropZone',
component: () => import('@/views/vue-use/elements/useDropZone.vue'),
name: 'useDropZone',
meta: {title: 'useDropZone', icon: 'star'}
},

]
},
Expand Down
6 changes: 4 additions & 2 deletions src/views/vue-use/elements/useDraggable.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<template>
<div style="position: relative">
<div ref="el" :style="style" style="position: fixed;background: #304156;height: 100px;width: 100px;color: white">
Drag me! I am at {{x}}, {{y}}
<div ref="el" :style="style" style="position: fixed;background: #304156;height: 100px;width: 100px;color: white;padding: 20px;line-height: 22px">
拖动我
<p>x:{{x}}</p>
<p>y:{{y}}</p>
</div>
</div>
</template>
Expand Down
48 changes: 48 additions & 0 deletions src/views/vue-use/elements/useDropZone.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<div class="flex">
<div>
<p style="margin-bottom: 20px">拖动图片到下面的灰色框</p>
<img src="/favicon.ico" alt="Drop me">

<div ref="dropZoneRef" style="background:gainsboro;height: 400px;width: 400px;margin-top: 20px">
<div v-for="(file, index) in filesData" :key="index" style="padding: 20px">
<p>文件名: {{ file.name }}</p>
<p>文件大小: {{ file.size }}</p>
<p>文件类型: {{ file.type }}</p>
</div>
</div>
</div>
</div>
</template>

<script>
export default {
name: "useDropZone"
}
</script>
<script setup>
import { ref } from 'vue'
import { useDropZone } from '@vueuse/core'
const filesData = ref([])
function onDrop(files) {
filesData.value = []
if (files) {
filesData.value = files.map(file => ({
name: file.name,
size: file.size,
type: file.type,
lastModified: file.lastModified,
}))
}
}
const dropZoneRef = ref(null)
const { isOverDropZone } = useDropZone(dropZoneRef, onDrop)
</script>

<style scoped>
</style>

0 comments on commit 6ccaaac

Please sign in to comment.