VueUse

Collection of essential Vue Composition Utilities for Vue 2 and 3

README

VueUse - Collection of essential Vue Composition Utilities VueUse - Collection of essential Vue Composition Utilities


Collection of essential Vue Composition Utilities

NPM versionNPM DownloadsDocs & DemosFunction CountGitHub stars


🚀 Features


- 🎪 [Interactive docs & demos](https://vueuse.org)
- 🕶 Seamless migration: Works for both Vue 3 and 2
- ⚡ Fully tree shakeable: Only take what you want, bundle size
- 🦾 Type Strong: Written in TypeScript, with TS Docs
- 🔋 SSR Friendly
- 🌎 No bundler required: Usable via CDN
- 🔩 Flexible: Configurable event filters and targets
- 🔌 Optional Add-ons: Router, Firebase, RxJS, etc.

🦄 Usage


  1. ```ts
  2. import { useLocalStorage, useMouse, usePreferredDark } from '@vueuse/core'

  3. export default {
  4.   setup() {
  5.     // tracks mouse position
  6.     const { x, y } = useMouse()

  7.     // is user prefers dark theme
  8.     const isDark = usePreferredDark()

  9.     // persist state in localStorage
  10.     const store = useLocalStorage(
  11.       'my-storage',
  12.       {
  13.         name: 'Apple',
  14.         color: 'red',
  15.       },
  16.     )

  17.     return { x, y, isDark, store }
  18.   },
  19. }
  20. ```

Refer to functions list or documentations for more details.

📦 Install


🎩 From v4.0, it works for Vue 2 & 3 within a single package by the power of vue-demi!


  1. ``` sh
  2. npm i @vueuse/core
  3. ```


From v6.0, VueUse requires vue >= v3.2 or @vue/composition-api >= v1.1


Demos


CDN


  1. ``` html
  2. <script src="https://unpkg.com/@vueuse/shared"></script>
  3. <script src="https://unpkg.com/@vueuse/core"></script>
  4. ```

It will be exposed to global as window.VueUse

🪴 Project Activity


Alt

🧱 Contribute


See the [Contributing Guide](https://vueuse.org/contributing)

🌸 Thanks


This project is heavily inspired by the following awesome projects.



👨‍🚀 Contributors


Financial Contributors on Open Collective



📄 License


MIT License © 2019-PRESENT Anthony Fu