UNPKG

1.97 kBMarkdownView Raw
1# Vuex 4
2
3This is the Vue 3 compatible version of Vuex. The focus is compatibility, and it provides the exact same API as Vuex 3, so users can reuse their existing Vuex code for Vue 3.
4
5## Status: Alpha
6
7All Vuex 3 feature works. There are a few breaking changes described in a later section, so please check them out. You can find basic usage with both option and composition API at `example` folder.
8
9Please note that it's still unstable, and there might be bugs. Please provide us feedback if you find anything. You may use [vue-next-webpack-preview](https://github.com/vuejs/vue-next-webpack-preview) to test out Vue 3 with Vuex 4.
10
11## Breaking changes
12
13### Installation process has changed
14
15To align with the new Vue 3 initialization process, the installation process of Vuex has changed as well.
16
17You should use a new `createStore` function to create a new store instance.
18
19```js
20import { createStore } from 'vuex'
21
22const store = createStore({
23 state () {
24 return {
25 count: 1
26 }
27 }
28})
29```
30
31> This is technically not a breaking change because you could still use `new Store(...)` syntax. However, to align with Vue 3 and also with Vue Router Next, we recommend users to use `createStore` function instead.
32
33Then to install Vuex to Vue app instance, pass the store instance instead of Vuex.
34
35```js
36import { createApp } from 'vue'
37import store from './store'
38import App from './APP.vue'
39
40const app = createApp(Counter)
41
42app.use(store)
43
44app.mount('#app')
45```
46
47## Kown issues
48
49- The code is kept as close to Vuex 3 code base as possible, and there're plenty of places where we should refactor. However, we are waiting for all of the test cases to pass before doing so (some tests require Vue 3 update).
50- TypeScript support is not ready yet. Please use JS environment to test this for now.
51
52## TODOs as of 4.0.0-alpha.1
53
54- Add TypeScript support
55- Make all unit test working
56- Refactor the codebase
57- Update the build system to align with Vue 3
58- Update docs