Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Vue composition-api composable components. i18n, validation, pagination, fetch, etc. +50 different composables

License

NotificationsYou must be signed in to change notification settings

pikax/vue-composable

Repository files navigation

vue-composable logo

CircleCICoverage Statusnpm versionbundle size

Out-of-the-box ready to use composables

  • 🌴 TreeShakable
  • 🧙‍♂️ Fully Typescript
  • 💚 Vue 3 and 2 support
  • 🔨 Vue Devtools support

Introduction

This library aim is to be one stop shop for many real-world composable functions, with aggressive tree-shaking to keep it light on your end code.

Installing

# @vue/composition-api# install with yarnyarn add @vue/composition-api vue-composable# install with npmnpm install @vue/composition-api vue-composable# vue 3# install with yarnyarn add vue-composable# install with npmnpm install vue-composable

Documentation

Check ourdocumentation

Composable

Event

  • Event - Attach event listener to a DOM element
  • Mouse Move - Attachmousemove listener to a DOM element
  • Resize - Attachresize listener to a DOM element
  • Scroll - Attachscroll listener to a DOM element
  • onOutsidePress - Execute callback when click is outside of element

Dom

Date

  • useNow : Return reactive custom timer with specified refresh rate
  • useDateNow : Returns reactiveDate.now() with custom refresh rate
  • usePerformanceNow : Returns reactiveperformance.now() with custom refresh rate

Format

  • format - Reactive string format
  • path - Retrieve object value based on string path

Breakpoint

MISC

Storage

  • WebStorage - Reactive access toStorage API,useLocalStorage anduseSessionStorage use this
  • storage - useslocalStorage or on safari private it usessessionStorage
  • localStorage - Reactive access to alocalStorage
  • sessionStorage - Reactive access to asessionStorage

Pagination

Validation

i18n

  • i18n - Simple i18n implementation with API inspired byvue-i18n

Intl

Promise

Meta

  • Title - reactivedocument.title

State

  • Timeline - Tracks variable history
  • Undo - Tracks variable history, to allowundo andredo
  • valueSync - syncs variables value, across multiplerefs

Web

External

New packages needed

Information

This is a monorepo project, please checkpackages

Devtools

There's some experimental devtools support starting from1.0.0-beta.6, only available forvue-next anddevtools beta 6.

Install plugin

To use devtools you need to install the plugin first:

import{createApp}from"vue";import{VueComposableDevtools}from"vue-composable";importAppfrom"./App.vue";constapp=createApp(App);app.use(VueComposableDevtools);// orapp.use(VueComposableDevtools,{id:"vue-composable",label:"devtool composables"});app.mount("#app");

Component State

To add properties to the component inspector tabComponentState

constbar="bar";useDevtoolsComponentState({    bar},{type:"custom composable"// change group});constbaz=()=>"baz";useDevtoolsComponentState({ baz});// no duplicates added by defaultuseDevtoolsComponentState({ baz});constthe=42;useDevtoolsComponentState({ the});// to allow multiple same keyuseDevtoolsComponentState({ the},{duplicate:true});// use a devtools api list directlyinterfaceStateBase{key:string;value:any;editable:boolean;objectType?:"ref"|"reactive"|"computed"|"other";raw?:string;type?:string;}useDevtoolsComponentState([{key:"_bar",type:"direct",value:"bar",editable:true},{key:"_baz",type:"direct",value:"baz",editable:false}]);// raw changeuseDevtoolsComponentState((payload,ctx)=>{payload.state.push(    ...[{key:"_bar",type:"raw",value:"bar",editable:true},{key:"_baz",type:"raw",value:"baz",editable:false}]);});

Timeline events

To add timeline events:

constid="vue-composable";constlabel="Test events";constcolor=0x92a2bf;const{ addEvent, pushEvent}=useDevtoolsTimelineLayer(id,description,color);// adds event to a specific point in the timelineaddEvent({time:Date.now(),data:{// data object},meta:{// meta object}});// adds event with `time: Date.now()`pushEvent({data:{// data object},meta:{// meta object}});

Inspector

Allows to create a new inspector for your data.

I'm still experimenting on how to expose this API on a composable, this will likely to change in the future, suggestions are welcome.

useDevtoolsInspector({id:"vue-composable",label:"test vue-composable"},// list of nodes, this can be reactive[{id:"test",label:"test - vue-composable",depth:0,state:{composable:[{editable:false,key:"count",objectType:"Ref",type:"setup",value:myRefValue}]}}]);

Typescript

Typescript@3.x is not supported, the supported version can be checked onpackage.json, usually is the latest version or the same major asvue-3

Contributing

You can contribute raising issues and by helping out with code.

Tests and Documentation are the most important things for me, because good documentation is really useful!

I really appreciate some tweaks or changes on how the documentation is displayed and how to make it easier to read.

Twitter:@pikax_dev

Build

# install packagesyarn# build and test for v2yarn build --version=2yarn test:vue2# build and test for v3yarn buildyarntest

New composable

  1. Fork it!
  2. Create your feature branch:git checkout -b feat/new-composable
  3. Commit your changes:git commit -am 'feat(composable): add a new composable'
  4. Push to the branch:git push origin feat/new-composable
  5. Submit a pull request

License

MIT

About

Vue composition-api composable components. i18n, validation, pagination, fetch, etc. +50 different composables

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors17


[8]ページ先頭

©2009-2025 Movatter.jp