]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
feat(nuxt): nuxt plugin working with Vue 2
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 19 Aug 2021 10:39:12 +0000 (12:39 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 19 Aug 2021 10:39:12 +0000 (12:39 +0200)
packages/nuxt/src/index.ts
packages/nuxt/templates/plugin.js

index 63ec1722de2acf9e0fedeeb18efcc287647a33ec..79e3dd7e5585b3c61ff811cd045f83e36f7e8660 100644 (file)
@@ -19,7 +19,6 @@ const module = defineNuxtModule<PiniaNuxtOptions>({
   defaults: {
     disableVuex: true,
   },
-  hooks: {},
   setup(options, nuxt) {
     // Disable default Vuex store (options.features only exists in Nuxt v2.10+)
     if (nuxt.options.features && options.disableVuex) {
@@ -47,8 +46,11 @@ export default module
 
 declare module '@nuxt/types' {
   export interface Context {
-    // TODO: test out if correct
-    // pinia: Pinia
+    /**
+     * Pinia instance attached to the app.
+     */
+    pinia: Pinia
+
     /**
      * Pinia instance attached to the app.
      */
index ac9e0b7c4f6e66c08c93f7b3892f0a764655887f..5d3e51b21d89007233794348a647fcce30ca9e63 100644 (file)
@@ -3,7 +3,7 @@ import { isVue2, Vue2 } from 'vue-demi'
 import { createPinia, setActivePinia, PiniaPlugin } from 'pinia'
 
 if (isVue2) {
-  Vue2(PiniaPlugin)
+  Vue2.use(PiniaPlugin)
 }
 
 /**
@@ -13,13 +13,15 @@ const PiniaNuxtPlugin = (context, inject) => {
   const pinia = createPinia()
   // add $pinia to the context
   inject('pinia', pinia)
-  // TO
   // to allow accessing pinia without the $
-  // context.pinia = pinia
+  context.pinia = pinia
 
   if (isVue2) {
     // simulate new Vue({ pinia })
     context.app.pinia = pinia
+  } else {
+    // TODO: does this work?
+    context.app.use(pinia)
   }
 
   setActivePinia(pinia)