From: Eduardo San Martin Morote Date: Thu, 14 Oct 2021 09:58:45 +0000 (+0200) Subject: fix(nuxt): inject pinia after installing the plugin X-Git-Tag: @pinia/nuxt@0.0.5~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=32dfdeca3d6413570d113f02314f57df9fecc42e;p=thirdparty%2Fvuejs%2Fpinia.git fix(nuxt): inject pinia after installing the plugin --- diff --git a/packages/nuxt/templates/plugin.js b/packages/nuxt/templates/plugin.js index 150812d9..d411db99 100644 --- a/packages/nuxt/templates/plugin.js +++ b/packages/nuxt/templates/plugin.js @@ -11,19 +11,21 @@ if (isVue2) { */ const PiniaNuxtPlugin = (context, inject) => { const pinia = createPinia() - // add $pinia to the context - inject('pinia', pinia) - // to allow accessing pinia without the $ - context.pinia = pinia - if (isVue2) { // simulate new Vue({ pinia }) context.app.pinia = pinia } else { - // TODO: does this work? context.app.use(pinia) } + // make sure to inject pinia after installing the plugin because in Nuxt 3, inject defines a non configurable getter + // on app.config.globalProperties + // add $pinia to the context + inject('pinia', pinia) + // to allow accessing pinia without the $ + // TODO: remove this in deprecation + context.pinia = pinia + setActivePinia(pinia) // add access to `$nuxt`