vue-composable
raw JSON →vue-composable (v1.0.0-beta.24) is a library of out-of-the-box ready-to-use composable functions for Vue 3 and Vue 2 (with @vue/composition-api). It provides tree-shakable, fully typed TypeScript composables for events (mouse move, resize, scroll, outside press), DOM (mouse distance from element), dates (now, dateNow, performanceNow), formatting (string format, object path), breakpoints (MatchMedia, Chrome, TailwindCSS responsive breakpoints), and miscellaneous utilities (sharedRef, vModel helper, injectFactory, interval, lockScroll). Its key differentiators from other composable libraries are aggressive tree-shaking to minimize bundle size, Vue Devtools support, and focus on real-world patterns. First beta released in 2020, with ongoing beta releases and no stable release yet. Requires Vue or @vue/composition-api as peer dependency.
Common errors
error Cannot read property 'ref' of undefined ↓
Vue.use(VueCompositionAPI) before mounting the app. error export 'format' was not found in 'vue-composable' ↓
error Default import is not a function ↓
import { useNow } from 'vue-composable'. error TypeError: Cannot read property 'setup' of undefined ↓
Warnings
breaking In v1.0.0-beta.22, 'format' composable renamed to 'useFormat' and 'path' composable renamed to 'usePath'. Old names cause runtime errors. ↓
breaking In v1.0.0-beta.15, the package changed from default export to named exports only. Code using `import VueComposable from 'vue-composable'` will break. ↓
breaking Vue 2 users must install @vue/composition-api as a peer dependency and register it before vue-composable. Missing this causes 'Cannot read property 'ref' of undefined'. ↓
deprecated Since v1.0.0-beta.10, the 'useInterval' composable was marked deprecated in favor of the more general 'useTimeout' with interval option. ↓
gotcha `sharedRef` uses BroadcastChannel API which is not supported in Node.js or older browsers. Falling back to localStorage leads to limited cross-tab reactivity. ↓
Install
npm install vue-composable yarn add vue-composable pnpm add vue-composable Imports
- useMouseMove wrong
const { useMouseMove } = require('vue-composable')correctimport { useMouseMove } from 'vue-composable' - useNow wrong
import useNow from 'vue-composable'correctimport { useNow } from 'vue-composable' - useBreakpoint
import { useBreakpoint } from 'vue-composable' - sharedRef
import { sharedRef } from 'vue-composable' - useFormat wrong
import { format } from 'vue-composable'correctimport { useFormat } from 'vue-composable'
Quickstart
// Install: npm install vue-composable vue (or @vue/composition-api if using Vue 2)
import { ref } from 'vue';
import { useMouseMove, useNow } from 'vue-composable';
export default {
setup() {
const { x, y } = useMouseMove();
const now = useNow({ refreshMs: 1000 });
return { x, y, now };
}
};