All Projects → PatrykWalach → vuex-composition-api

PatrykWalach / vuex-composition-api

Licence: MIT license
www.npmjs.com/package/vuex-composition-api

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to vuex-composition-api

vue-unstated
A tiny state management library for Vue Composition API.
Stars: ✭ 30 (+30.43%)
Mutual labels:  composition-api
vue-tiny-validate
💯 Tiny Vue Validate Composition
Stars: ✭ 80 (+247.83%)
Mutual labels:  composition-api
vuex-hooks
Typescript enabled vuex composition-api hooks
Stars: ✭ 12 (-47.83%)
Mutual labels:  composition-api
vue3-form-validation
Vue Composition Function for Form Validation
Stars: ✭ 18 (-21.74%)
Mutual labels:  composition-api
vue-snippets
Visual Studio Code Syntax Highlighting For Vue3 And Vue2
Stars: ✭ 25 (+8.7%)
Mutual labels:  composition-api
webneko-blog
✍️ Technical Blog written by @jiyuujin
Stars: ✭ 14 (-39.13%)
Mutual labels:  composition-api
v-intl
Add i18n to your awesome Vue 3 app 🔉
Stars: ✭ 13 (-43.48%)
Mutual labels:  composition-api
vue2-helpers
🔧 A util package to use Vue 2 with Composition API easily
Stars: ✭ 64 (+178.26%)
Mutual labels:  composition-api
v-pip
🖼 Tiny vue wrapper for supporting native picture-in-picture mode.
Stars: ✭ 30 (+30.43%)
Mutual labels:  composition-api
2019-ncov-vue3-version
新型冠状病毒实时疫情 Vue-Compostion-Api版本 (Vue3 + TypeScript)
Stars: ✭ 55 (+139.13%)
Mutual labels:  composition-api
ts-express-vue3
Boilerplate for Express + Vue 3 with Typescript and Composition API
Stars: ✭ 15 (-34.78%)
Mutual labels:  composition-api
goldfish
A development framework for Alipay Mini Program.
Stars: ✭ 69 (+200%)
Mutual labels:  composition-api
vue3-realworld-example-app
Explore the charm of Vue composition API! Vite?
Stars: ✭ 364 (+1482.61%)
Mutual labels:  composition-api
nuxt-realworld
🛠 Built a Example App of RealWorld with Nuxt & Composition API ⚗️
Stars: ✭ 127 (+452.17%)
Mutual labels:  composition-api
pinia
🍍 Intuitive, type safe, light and flexible Store for Vue using the composition api with DevTools support
Stars: ✭ 9,952 (+43169.57%)
Mutual labels:  composition-api
assembler
Functional, type-safe, stateless reactive Java API for efficient implementation of the API Composition Pattern for querying/merging data from multiple datasources/services, with a specific focus on solving the N + 1 query problem
Stars: ✭ 102 (+343.48%)
Mutual labels:  composition-api
vue3-demo
💡 vue3新特性示例: 响应式API、组合式API、TodoMVC
Stars: ✭ 114 (+395.65%)
Mutual labels:  composition-api
veact
Mutable state enhancer library for React based on @vuejs
Stars: ✭ 62 (+169.57%)
Mutual labels:  composition-api
vuse-rx
Vue 3 + rxjs = ❤
Stars: ✭ 52 (+126.09%)
Mutual labels:  composition-api
Vue3 News
🔥 Find the latest breaking Vue3、Vue CLI 3+ & Vite News. (2021)
Stars: ✭ 2,416 (+10404.35%)
Mutual labels:  composition-api

Vuex Composition Modules

Build Status downloads codecov code style: prettier

This project allows for experimental use of Vuex 5 composition API in Vue 3 .

Table of Contents

Getting started

  1. Install vuex

    import { createApp } from 'vue'
    import { createVuex } from 'vuex-composition-api'
    const vuex = createVuex()
    
    const app = createApp(App).use(vuex)
    // ...
  2. Define store/stores

    import { defineStore } from 'vuex-composition-api'
    export const counterStore = defineStore('counter', () => {
      const value = ref(0)
    
      function increment() {
        value.value++
      }
    
      return { value, increment }
    })
  3. Use store

    <template>
      <h1>Counter value: {{counter.value}}</h1>
      <button @click="counter.increment">INCREMENT</button>
    </template>
    
    <script lang="ts">
      import { definecComponent } from 'vue'
      import { useStore } from 'vuex-composition-api'
      import { counterStore } from './counter'
    
      export default definecComponent({
        setup() {
          const counter = useStore(counterStore)
    
          return {
            counter,
          }
        },
      })
    </script>

Composing

import { defineStore } from 'vuex-composition-api'
import { authStore } from './auth'

export const user = defineStore('user', ({ use }) => {
  const auth = use(authStore)

  function login(login, password) {
    auth.user(login, password)
  }

  return { login }
})

Plugins

  1. Create plugin

    function axiosPlugin(provide) {
      provide('axios', axios)
    }
  2. Install plugin

    import { createApp } from 'vue'
    import { createVuex } from 'vuex-composition-api'
    
    const vuex = createVuex({ plugins: [axiosPlugin] })
    
    const app = createApp(App).use(vuex)
    //...
  3. Use plugin

    import { defineStore } from 'vuex-composition-api'
    
    export const authStore = defineStore('auth', ({ axios }) => {
      function user(login, password) {
        axios.post('/login', {
          login,
          password,
        })
      }
    
      return { login }
    })

API

defineStore

function defineStore(name: string, setup: StoreSetup): Store

createVuex

interface Vuex {
  install(app: App): App
  store(store: Store): T
}

function createVuex(options: { plugins: Plugin[] }): Vuex

useStore

function useStore(storeOptions: Store): T
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].