3.0.0 • Published 5 years ago
vuex-composition-api v3.0.0
��# Vuex Composition Modules
This project allows for experimental use of Vuex 5 composition API in Vue 3 .
Table of Contents
Getting started
- Install vuex - import { createApp } from 'vue' import { createVuex } from 'vuex-composition-api' const vuex = createVuex() const app = createApp(App).use(vuex) // ...
- 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 } })
- 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
- Create plugin - function axiosPlugin(provide) { provide('axios', axios) }
- Install plugin - import { createApp } from 'vue' import { createVuex } from 'vuex-composition-api' const vuex = createVuex({ plugins: [axiosPlugin] }) const app = createApp(App).use(vuex) //...
- 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): StorecreateVuex
interface Vuex {
  install(app: App): App
  store(store: Store): T
}
function createVuex(options: { plugins: Plugin[] }): VuexuseStore
function useStore(storeOptions: Store): T3.0.0
5 years ago
3.0.0-beta.0
6 years ago
2.0.1
6 years ago
2.0.0
6 years ago
2.0.0-beta.0
6 years ago
1.0.0
6 years ago
0.2.1
6 years ago
0.1.15
6 years ago
0.1.14
6 years ago
0.1.13
6 years ago
0.1.12
6 years ago
0.1.11
6 years ago
0.1.10
6 years ago
0.1.8
6 years ago
0.1.7
6 years ago
0.1.6
6 years ago
0.1.5
6 years ago
0.1.4
6 years ago
0.1.3
6 years ago