You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/README.md
+20Lines changed: 20 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,8 @@ We will be using ES2015 syntax for code examples for the rest of the docs. If yo
16
16
17
17
After [installing](../installation.md) Vuex, let's create a store. It is pretty straightforward - just provide an initial state object, and some mutations:
18
18
19
+
#### Vuex 3.x (for Vue 2)
20
+
19
21
```js
20
22
importVuefrom'vue'
21
23
importVuexfrom'vuex'
@@ -34,6 +36,24 @@ const store = new Vuex.Store({
34
36
})
35
37
```
36
38
39
+
#### Vuex 4.x (for Vue 3)
40
+
41
+
```js
42
+
import { createStore } from'vuex'
43
+
import { createApp } from'vue'
44
+
45
+
conststore=createStore({
46
+
state () {
47
+
return {
48
+
count:1
49
+
}
50
+
}
51
+
})
52
+
53
+
constapp=createApp({ /* your root component */ })
54
+
app.use(store)
55
+
```
56
+
37
57
Now, you can access the state object as `store.state`, and trigger a state change with the `store.commit` method:
0 commit comments