@vueuse/gesture is a comprehensive collection of Vue Composables designed to provide robust and interactive gesture support for Vue applications. It offers a suite of hooks for various pointer and touch gestures, including `useDrag`, `useMove`, `useHover`, `useScroll`, `useWheel`, `usePinch`, and a generic `useGesture` for handling multiple interactions simultaneously. The library is currently stable at version `2.0.0` (last published approximately two years ago) and is an active part of the broader VueUse ecosystem. Its key differentiators include seamless compatibility with both Vue 2 and Vue 3 environments via `vue-demi`, offering both composable function-based and directive-based (e.g., `v-drag`) APIs. It is a direct port of the well-known `react-use-gesture` library, bringing similar declarative and powerful animation possibilities to the Vue ecosystem, and is explicitly designed to integrate smoothly with animation libraries like `@vueuse/motion`.
npm install vue-use-gestureVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic draggable element using the `useDrag` composable, integrating with `vue-use-spring` for smooth animation and including the essential `touch-action` CSS property.
Update your package.json to `@vueuse/gesture` and adjust import paths accordingly. E.g., `npm install @vueuse/gesture` or `yarn add @vueuse/gesture`.
Add `touch-action: none;` to the CSS of your draggable element, or apply it via inline style as shown in the quickstart example.
Install `@vue/composition-api` (`npm install @vue/composition-api`) and ensure it's registered with Vue (e.g., `Vue.use(VueCompositionAPI)`).
Import the specific directive (e.g., `DragDirective`) and register it: `import { DragDirective } from '@vueuse/gesture'; app.directive('drag', DragDirective);`.Change the import path to `@vueuse/gesture`: `import { useDrag } from '@vueuse/gesture'`.Globally register the `DragDirective` at your app's entry point: `import { DragDirective } from '@vueuse/gesture'; app.directive('drag', DragDirective);`.For Vue 2, ensure `@vue/composition-api` is installed and registered. Ensure all `use*` hooks are called directly within the `setup` function of a component.