Skip to content

Commit

Permalink
incorrect module foo
Browse files Browse the repository at this point in the history
  • Loading branch information
dyf19118 authored Apr 18, 2019
1 parent eb1c9db commit d354d32
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions docs/guide/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ export default {
// Server-side only
serverPrefetch () {
// register store module on server-side and dont preserve state at current step,
// since module foo's state has not been initiated yet.
this.registerFoo()
return this.fooInc()
},
Expand All @@ -251,7 +253,7 @@ export default {
const alreadyIncremented = !!this.$store.state.foo
// We register the foo module
this.registerFoo()
this.registerFoo(true)
if (!alreadyIncremented) {
this.fooInc()
Expand All @@ -265,9 +267,9 @@ export default {
},
methods: {
registerFoo () {
registerFoo (shoudPreserve = false) {
// Preserve the previous state if it was injected from the server
this.$store.registerModule('foo', fooStoreModule, { preserveState: true })
this.$store.registerModule('foo', fooStoreModule, { preserveState: shoudPreserve })
},
fooInc () {
Expand Down

1 comment on commit d354d32

@dyf19118
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this modification, coding follows the guide will cause an error: Cannot read property 'count' of undefined. This is caused by registering foo module on server-side without adding state to store. Since previous state was preserved, there's no 'foo.count' property on global state object when fooInc method in serverPrefetch option was called.

Please sign in to comment.