Created
August 17, 2020 15:58
-
-
Save CheyenneForbes/be9c549fd1c01d9d0c2b46ee26031bba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import storeModule from './store-module'; | |
export default async ({ Vue, router, store }) => { | |
Vue.use(storeModule, router, store, { | |
preserveState: preserveState | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<q-page padding> | |
<div>refresh and '$store.state.storeModule' won't exist</div> | |
{{$store.state.storeModule ? JSON.stringify($store.state.storeModule) : 'not there, placeholder'}} | |
</q-page> | |
</template> | |
<script> | |
export default { | |
name: 'ComponentThatFetch', | |
serverPrefetch () { | |
this.$store.dispatch({ | |
type: 'storeModule/addData', | |
data: {test: 'testData'} | |
}); | |
}, | |
} | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import storeModule from './store-module'; | |
export default async ({ Vue, router, store, ssrContext }) => { | |
Vue.use(storeModule, router, store, { | |
request: ssrContext.req | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let storeModule = { | |
namespaced: true, | |
state: () => ({ | |
data: {} | |
}), | |
mutations: { | |
SET_DATA(state, payload) { | |
state.data = payload.data; | |
} | |
}, | |
actions: { | |
setData(context, payload) { | |
context.commit({ | |
type: 'SET_DATA', | |
data: payload.data | |
}); | |
} | |
} | |
}; | |
export default { | |
install: function install(Vue, router, store, options) { | |
//do_stuff_with(router, options.request) | |
store.registerModule('storeModule', storeModule, {preserveState: options.preserveState}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment