useDraggable ​
Provides drag-and-drop props and reactive dragOptions for components that use Sortable.js (via vue-draggable-next).
File: vue/src/js/hooks/useDraggable.js
Props factory: makeDraggableProps
Usage ​
js
import { useDraggable, makeDraggableProps } from '@/hooks'
// In your component
const props = defineProps({ ...makeDraggableProps() })
const { dragOptions } = useDraggable(props, context)html
<draggable v-bind="dragOptions" v-model="items">
<template #item="{ element }">...</template>
</draggable>Props (via makeDraggableProps) ​
| Prop | Type | Default | Description |
|---|---|---|---|
draggable | Boolean | false | Enables drag-and-drop when true |
orderKey | String | 'position' | The model key that stores the sort order |
Returns ​
| Name | Type | Description |
|---|---|---|
dragOptions | ComputedRef<Object> | Options object to pass to <draggable>. Contains disabled (flipped from props.draggable) and animation: 150. |
Notes ​
- When
draggableisfalse,dragOptions.disabledistrueand the list is static. useRepeateranduseFile/useImagespreadmakeDraggablePropsinto their own prop definitions, inheriting drag support automatically.
See Also ​
- useRepeater — uses
draggable+orderKeyto reorder blocks - useFile — file list supports draggable reorder