Skip to content
This repository was archived by the owner on Mar 8, 2025. It is now read-only.

Commit 113ac0b

Browse files
committed
✨ Add lazy store example
1 parent 1bc5afb commit 113ac0b

File tree

11 files changed

+37
-1
lines changed

11 files changed

+37
-1
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"interfaces": "typescript",
2929
"decorators": "typescript",
3030
"mixins": "vue",
31+
"store-*": "vuex",
3132
"use": "mappings",
3233
},
3334

src/core/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Be careful modifying these core folders

src/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import App from '@/App.vue'
2121
import '@/core/styles/css/main.css'
2222
import '@/core/styles/scss/main.scss'
2323

24+
import '@/styles/custom.scss'
25+
2426
Vue.mixin(globalMixin)
2527

2628
Vue.use(clientApi)

src/pages/projects/[slug]/index.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,22 @@
55
</div>
66
</template>
77
<script>
8-
import { defineComponent } from '@vue/composition-api'
8+
import { store } from '@/store'
9+
import { defineComponent, onUnmounted } from '@vue/composition-api'
10+
import { projectDetail } from '@/store-lazy/project-detail'
911
export default defineComponent({
1012
name: 'ProjectWrapperPage',
13+
setup() {
14+
// Dynamic vuex module
15+
if (!store.hasModule('projectDetail')) {
16+
store.registerModule('projectDetail', projectDetail, {
17+
preserveState: false,
18+
})
19+
}
20+
// Only exist when viewing this page and it's sub-pages
21+
onUnmounted(() => {
22+
store.unregisterModule('projectDetail')
23+
})
24+
},
1125
})
1226
</script>

src/store-lazy/.gitkeep

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const actions = {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const projectDetailActions = {}
2+
3+
export const projectDetailMutations = {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const getters = {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { state } from './state'
2+
import { getters } from './getters'
3+
import { mutations } from './mutations'
4+
import { actions } from './actions'
5+
export const projectDetail = {
6+
namespaced: true,
7+
state,
8+
getters,
9+
mutations,
10+
actions,
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const mutations = {}

0 commit comments

Comments
 (0)