Skip to content

Instantly share code, notes, and snippets.

@CheyenneForbes
Created August 17, 2020 15:58
Show Gist options
  • Save CheyenneForbes/be9c549fd1c01d9d0c2b46ee26031bba to your computer and use it in GitHub Desktop.
Save CheyenneForbes/be9c549fd1c01d9d0c2b46ee26031bba to your computer and use it in GitHub Desktop.
import storeModule from './store-module';
export default async ({ Vue, router, store }) => {
Vue.use(storeModule, router, store, {
preserveState: preserveState
});
}
<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>
import storeModule from './store-module';
export default async ({ Vue, router, store, ssrContext }) => {
Vue.use(storeModule, router, store, {
request: ssrContext.req
});
}
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