返回 slidev
Draggable.vue
根目录 / packages / client / internals / Draggable.vue
1 <script setup lang="ts">
2 import { useDraggable, useLocalStorage } from '@vueuse/core'
3 import { ref } from 'vue'
4
5 const props = defineProps<{
6 storageKey?: string
7 initial?: { x: number, y: number }
8 }>()
9
10 const el = ref<HTMLElement | null>(null)
11 const initial = props.initial ?? { x: 0, y: 0 }
12 const point = props.storageKey
13 ? useLocalStorage(props.storageKey, initial)
14 : ref(initial)
15 const { style } = useDraggable(el, { initialValue: point })
16 </script>
17
18 <template>
19 <div ref="el" class="fixed" :style="style">
20 <slot />
21 </div>
22 </template>
23
23 lines Plain Text