Code Monkey home page Code Monkey logo

vueuse's Introduction

logo

NPM version Storybook Demos NPM Downloads GitHub last commit GitHub issues GitHub stars

Collection of essential Vue Composition API (inspired by react-use)

๐Ÿš€ Features

  • 0 dependencies โšก No worry about your bundle size
  • Fully tree shakable ๐ŸŒด Only take what you want
  • Seamless migration ๐Ÿ•ถ Works for both Vue 3.x and 2.x
  • Browser compatible ๐ŸŒ Use it without complex building tools
  • Intractive docs & demos ๐ŸŽช Check out the Storybook!
  • Optional Add-ons ๐Ÿ”Œ Firebase, vue-i18n, etc

๐Ÿฆ„ Usage

import { useMouse, usePreferredDark, useLocalStorage } from '@vueuse/core'

new Vue({
  setup() {
    // tracks mouse position
    const { x, y } = useMouse()

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

    // persist state in localStorage
    const state = useLocalStorage(
      'my-storage', 
      {
        name: 'Apple',
        color: 'red',
      },
    )

    return { x, y, isDark, state }
  }
})

Refer to functions and documentations for more details.

๐Ÿ“ฆ Install

for Vue 3.x (vue-next), demo here

npm i @vueuse/core@vue3

for Vue 2.x with composition-api polyfill

npm i @vue/composition-api @vueuse/core@vue2

Please register the Composition API Plugin before using APIs.

CDN

<!-- For Vue 3.x -->
<script src="https://unpkg.com/@vueuse/core@vue3"></script> 

<!-- For Vue 2.x -->
<script src="https://unpkg.com/@vueuse/core@vue2"></script>

It will be exposed to global variable as window.VueUse

โšก Functions

You can checkout the full documents and live demos in Storybook.

More functions to be added. Please keep turned. (PRs are also welcome!)

๐Ÿ”Œ Add-ons

The core package aims to be lightweight and dependence free. While the add-ons are wrapping popular packages into the consistent API style.

๐Ÿ”ฌ Technical Details

The Versioning

For every release, it will release two version of this package. The 3.x.x is used for Vue 3.x and the 2.x.x is used for 2.x. We use the major version number to distinguish the different target version will the minor and patch numbers are shared in both packages.

Different between 3.x and 2.x

Since the Composition API will be available in 3.x. Using it in 2.x require you use a polyfill. For 3.x build, we use the API from @vue/runtime-dom, and for 2.x, it's @vue/composition-api. All the functions exported in this package behaves the same.

// 3.x build
import { ref } from '@vue/runtime-dom'

// 2.x build
import { ref } from '@vue/composition-api'

๐Ÿงฑ Contribute

See the Contributing Guide

๐ŸŒธ Thanks

This project is heavily inspired by following awesome projects.

Thanks!

๐Ÿ“„ License

MIT License ยฉ 2019-2020 Anthony Fu

vueuse's People

Contributors

antfu avatar joaoeudes7 avatar renovate-bot avatar renovate[bot] avatar romansp avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.