You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.5 KiB

  1. <p align="center">
  2. <a href="https://github.com/vueuse/vueuse#gh-light-mode-only">
  3. <img src="https://raw.githubusercontent.com/vueuse/vueuse/main/packages/public/logo-vertical.png#gh-light-mode-only" alt="VueUse - Collection of essential Vue Composition Utilities" width="300">
  4. </a>
  5. <a href="https://github.com/vueuse/vueuse#gh-dark-mode-only">
  6. <img src="https://raw.githubusercontent.com/vueuse/vueuse/main/packages/public/logo-vertical-dark.png#gh-dark-mode-only" alt="VueUse - Collection of essential Vue Composition Utilities" width="300">
  7. </a>
  8. <br>
  9. Collection of essential Vue Composition Utilities
  10. </p>
  11. <p align="center">
  12. <a href="https://www.npmjs.com/package/@vueuse/core" target="__blank"><img src="https://img.shields.io/npm/v/@vueuse/core?color=a1b858&label=" alt="NPM version"></a>
  13. <a href="https://www.npmjs.com/package/@vueuse/core" target="__blank"><img alt="NPM Downloads" src="https://img.shields.io/npm/dm/@vueuse/core?color=50a36f&label="></a>
  14. <a href="https://vueuse.org" target="__blank"><img src="https://img.shields.io/static/v1?label=&message=docs%20%26%20demos&color=1e8a7a" alt="Docs & Demos"></a>
  15. <img alt="Function Count" src="https://vueuse.org/badge-function-count.svg">
  16. <br>
  17. <a href="https://github.com/vueuse/vueuse" target="__blank"><img alt="GitHub stars" src="https://img.shields.io/github/stars/vueuse/vueuse?style=social"></a>
  18. </p>
  19. <p align="center">
  20. <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
  21. <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'>
  22. </a>
  23. </p>
  24. ## 🚀 Features
  25. - 🎪 [**Interactive docs & demos**](https://vueuse.org)
  26. - 🕶 **Seamless migration**: Works for **both** Vue 3 and 2
  27. -**Fully tree shakeable**: Only take what you want, [bundle size](https://vueuse.org/export-size)
  28. - 🦾 **Type Strong**: Written in [TypeScript](https://www.typescriptlang.org/), with [TS Docs](https://github.com/microsoft/tsdoc)
  29. - 🔋 **SSR Friendly**
  30. - 🌎 **No bundler required**: Usable via CDN
  31. - 🔩 **Flexible**: Configurable event filters and targets
  32. - 🔌 **Optional [Add-ons](https://vueuse.org/add-ons)**: Router, Firebase, RxJS, etc.
  33. ## 🦄 Usage
  34. ```ts
  35. import { useLocalStorage, useMouse, usePreferredDark } from '@vueuse/core'
  36. export default {
  37. setup() {
  38. // tracks mouse position
  39. const { x, y } = useMouse()
  40. // is user prefers dark theme
  41. const isDark = usePreferredDark()
  42. // persist state in localStorage
  43. const store = useLocalStorage(
  44. 'my-storage',
  45. {
  46. name: 'Apple',
  47. color: 'red',
  48. },
  49. )
  50. return { x, y, isDark, store }
  51. },
  52. }
  53. ```
  54. Refer to [functions list](https://vueuse.org/functions) or [documentations](https://vueuse.org/) for more details.
  55. ## 📦 Install
  56. > 🎩 From v4.0, it works for Vue 2 & 3 **within a single package** by the power of [vue-demi](https://github.com/vueuse/vue-demi)!
  57. ```bash
  58. npm i @vueuse/core
  59. ```
  60. [Add ons](https://vueuse.org/add-ons.html) | [Nuxt Module](https://vueuse.org/guide/index.html#nuxt)
  61. > From v6.0, VueUse requires `vue` >= v3.2 or `@vue/composition-api` >= v1.1
  62. ###### Demos
  63. - [Vite + Vue 3](https://github.com/vueuse/vueuse-vite-starter)
  64. - [Nuxt 3 + Vue 3](https://github.com/antfu/vitesse-nuxt3)
  65. - [Webpack + Vue 3](https://github.com/vueuse/vueuse-vue3-example)
  66. - [Nuxt 2 + Vue 2](https://github.com/antfu/vitesse-nuxt-bridge)
  67. - [Vue CLI + Vue 2](https://github.com/vueuse/vueuse-vue2-example)
  68. ### CDN
  69. ```html
  70. <script src="https://unpkg.com/@vueuse/shared"></script>
  71. <script src="https://unpkg.com/@vueuse/core"></script>
  72. ```
  73. It will be exposed to global as `window.VueUse`
  74. ## 🪴 Project Activity
  75. ![Alt](https://repobeats.axiom.co/api/embed/a406ba7461a6a087dbdb14d4395046c948d44c51.svg "Repobeats analytics image")
  76. ## 🧱 Contribute
  77. See the [**Contributing Guide**](https://vueuse.org/contributing)
  78. ## 🌸 Thanks
  79. This project is heavily inspired by the following awesome projects.
  80. - [streamich/react-use](https://github.com/streamich/react-use)
  81. - [u3u/vue-hooks](https://github.com/u3u/vue-hooks)
  82. - [logaretm/vue-use-web](https://github.com/logaretm/vue-use-web)
  83. - [kripod/react-hooks](https://github.com/kripod/react-hooks)
  84. And thanks to [all the contributors on GitHub](https://github.com/vueuse/vueuse/graphs/contributors)!
  85. ## 👨‍🚀 Contributors
  86. ### Financial Contributors on Open Collective
  87. <a href="https://opencollective.com/vueuse"><img src="https://opencollective.com/vueuse/individuals.svg?width=890"></a>
  88. ## 📄 License
  89. [MIT License](https://github.com/vueuse/vueuse/blob/main/LICENSE) © 2019-PRESENT [Anthony Fu](https://github.com/antfu)