Giter VIP home page Giter VIP logo

vuses's Introduction

vuses

styled with prettier Travis Coveralls dependencies GitHub stars GitHub forks GitHub last commit License

Vue Hooks that built with Vue Composition Api

For Vue 3, but also compatible with Vue 2

Usage

if you are using Vue2, you must first import @vue/composition-api package:

import Vue from 'vue'
import CompositionAPI from '@vue/composition-api'

Vue.use(CompositionAPI) // required for Vue2

and then:

<template>
  <div>
    <p>{{ counter }}</p>
    <button @click="inc">inc</button>
    <button @click="dec">dec</button>
  </div>
</template>

<script>
  import { useCounter } from 'vuses'

  export default {
    setup () {
      const [counter, { inc, dec }] = useCounter()
      return {
        counter,
        inc,
        dec
      }
    }
  }
</script>

Hooks Plan

  • State:
    • useCounter and useNumber: tracks state of a number
    • useToggle and useBoolean: tracks state of a boolean
    • usePrevious: returns the previous state
    • useDefault: returns the default value when state is null or undefined
    • useGetSet: returns state getter get() instead of raw state
    • useGetSetState: as if useGetSet and useSetState had a baby
    • useObservable: tracks latest value of an Observable
    • useStateList: circularly iterates over an array
    • useList: tracks state of an array
    • useMap: tracks state of an object
    • useStateValidator: tracks state of an object
  • Sensors:
    • useWindowSize: tracks Widnow dimensions(browser environment is required)
    • useWindowScroll: tracks Window scroll position(browser environment is required)
    • useBattery: tracks device battery state
    • useGeolocation: tracks geo location state of user's device
    • useIdle: tracks whether user is being inactive
    • useIntersection: tracks an HTML element's intersection
    • useEvent: subscribe to events
    • useMedia: tracks state of a CSS media query
    • useMediaDevices: tracks connected hardware devices
    • useDeviceMotion: tracks state of device's motion sensor
    • useMouse: tracks state of mouse position
    • useNetwork: tracks state of user's internet connection
    • usePageLeave: triggers when mouse leaves page boundaries
  • Side Effects:
    • useDebounce: debounces a function
    • useThrottle: throttles a function
    • useAsync: resolves an async function
    • useLocalStorage: manages a value in localStorage
    • useSessionStorage: manages a value in sessionStorage
    • useFavicon: sets favicon of the page
    • useTitle: sets title of the page
    • usePermission: query permission status for browser APIs
  • UI:
    • useClickAway: triggers callback when user clicks outside target area
    • useCss: dynamically adjusts CSS
    • useFullscreen: display an element or video full-screen
    • useWait: complex waiting management for UIs
  • Animations:
    • useTimeout: re-renders component after a timeout
    • useInterval: re-renders component on a set interval using setInterval

Contributing

Please see Contributing

Contributors

License

MIT

vuses's People

Contributors

dependabot-preview[bot] avatar jo0ger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.