1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| <script setup> import { ref, onMounted, onUnmounted } from 'vue'
const leftWidth = ref(300) let isDragging = false
const startDrag = (e) => { isDragging = true document.addEventListener('mousemove', onDrag) document.addEventListener('mouseup', stopDrag) e.preventDefault() }
const onDrag = (e) => { if (!isDragging) return const container = document.querySelector('.container') const rect = container.getBoundingClientRect() const newWidth = e.clientX - rect.left if (newWidth > 100 && newWidth < rect.width - 100) { leftWidth.value = newWidth } }
const stopDrag = () => { isDragging = false document.removeEventListener('mousemove', onDrag) document.removeEventListener('mouseup', stopDrag) }
onUnmounted(() => { document.removeEventListener('mousemove', onDrag) document.removeEventListener('mouseup', stopDrag) }) </script>
|