From: Eduardo San Martin Morote Date: Wed, 3 Mar 2021 16:30:03 +0000 (+0100) Subject: feat(nuxt): add buildModule X-Git-Tag: v0.2.0~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b1566f7586cbd8f444fff48da4b5a8dfb5cb0951;p=thirdparty%2Fvuejs%2Fpinia.git feat(nuxt): add buildModule --- diff --git a/nuxt/plugin.js b/nuxt/plugin.js index abbe3581..12b9e116 100644 --- a/nuxt/plugin.js +++ b/nuxt/plugin.js @@ -1,20 +1,26 @@ // @ts-check import Vue from 'vue' // @ts-ignore: this must be pinia to load the local module -import { setActiveReq, setStateProvider, getRootState } from 'pinia' +import { setActivePinia, PiniaPlugin, createPinia } from 'pinia' + +Vue.use(PiniaPlugin) /** @type {import('@nuxt/types').Plugin} */ -const myPlugin = (context) => { - // console.log('🍍 Pinia Nuxt plugin installed') +const myPlugin = (context, inject) => { + // console.log(context) + + const pinia = createPinia() + context.app.pinia = pinia + setActivePinia(pinia) + + inject('pinia', pinia) - // TODO: figure this out if (process.server) { - setActiveReq(context.req) context.beforeNuxtRender(({ nuxtState }) => { - nuxtState.pinia = getRootState(context.req) + nuxtState.pinia = pinia.state.value }) } else if (context.nuxtState && context.nuxtState.pinia) { - setStateProvider(() => context.nuxtState.pinia) + pinia.state.value = context.nuxtState.pinia } }