3.0.0 • Published 4 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): Store
createVuex
interface Vuex {
install(app: App): App
store(store: Store): T
}
function createVuex(options: { plugins: Plugin[] }): Vuex
useStore
function useStore(storeOptions: Store): T
3.0.0
4 years ago
3.0.0-beta.0
4 years ago
2.0.1
5 years ago
2.0.0
5 years ago
2.0.0-beta.0
5 years ago
1.0.0
5 years ago
0.2.1
5 years ago
0.1.15
5 years ago
0.1.14
5 years ago
0.1.13
5 years ago
0.1.12
5 years ago
0.1.11
5 years ago
0.1.10
5 years ago
0.1.8
5 years ago
0.1.7
5 years ago
0.1.6
5 years ago
0.1.5
5 years ago
0.1.4
5 years ago
0.1.3
5 years ago