0.0.16 • Published 1 year ago

vue-hook-svc v0.0.16

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

vue-hook-svc

npm npm Build Status License

A service、state manager for Vue2/3. minzipped less than 300 bytes

English | 中文

Advantage

  • ~300 bytes min+gz.
  • Minimal API 5 minutes to learn, easy to use.
  • Written in TypeScript offer you more types.

Installation

npm install vue-hook-svc --save

if in Vue2, you need @vue/composition-api installed

npm i @vue/composition-api --save

Usage & Example

declare a service

// declare a service
import { svc } from 'vue-hook-svc';

export class SomeService extends svc.ServiceBase {
    state = {
        show: true
    };

    toggle() {
        this.state.show = !this.state.show;
    }
}

// create a global service
export const globalSomeSvc = svc.createSingleton(SomeService);
// create a service func depends on the component's lifecycle
export const useSomeSvc = svc.createUseService(GlobalService);

use in global, anywhere

// use in global, anywhere
import { globalSomeSvc } from '.';

globalSomeSvc.state.show = false;

use with the component's lifecycle

// use with the component's lifecycle
// in setup of vue's file

// then all children can use `useSomeSvc` to get the same instance.
const svc = useSomeSvc();

use in template

<!-- use in template -->
<template>
    <div>
        <button @click="() => svc.toggle()">update</button>
        <span v-if="svc.state.show">...</span>
    </div>
</template>

License

MIT

0.0.16

1 year ago

0.0.13

2 years ago

0.0.15

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.5

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago