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/state.md
+40-2Lines changed: 40 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,9 @@
1
1
# State management
2
2
3
-
-[Modules](#modules)
4
-
-[Helpers](#helpers)
3
+
-[State management](#state-management)
4
+
-[Modules](#modules)
5
+
-[Helpers](#helpers)
6
+
-[Module Nesting](#module-nesting)
5
7
6
8
## Modules
7
9
@@ -26,3 +28,39 @@ export default {
26
28
},
27
29
}
28
30
```
31
+
32
+
## Module Nesting
33
+
34
+
Vuex modules can be nested, which sometimes makes sense for organizational purposes. For example, if you created these files:
35
+
36
+
```js
37
+
// @file src/state/modules/dashboard.js
38
+
39
+
exportconststate= {
40
+
role:'project-manager',
41
+
}
42
+
```
43
+
44
+
```js
45
+
// @file src/state/modules/dashboard/videos.js
46
+
47
+
exportconststate= {
48
+
all: [],
49
+
}
50
+
51
+
exportconstgetters= {
52
+
favorited(state) {
53
+
returnstate.all.filter((video) =>video.favorited)
54
+
},
55
+
}
56
+
```
57
+
58
+
Then you'd be able to access those modules with:
59
+
60
+
```js
61
+
store.state.dashboard.role
62
+
store.state.dashboard.videos.all
63
+
store.getters['dashboard/videos/favorited']
64
+
```
65
+
66
+
As you can see, placing the `videos` module in a folder called `dashboard` automatically nests it underneath the `dashboard` namespace. This works even if a `dashboard.js` file doesn't exist. You can also have as many levels of nesting as you want.
0 commit comments