]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: Nuxt 2 --> 3 (#2766)
authorDavid Mears <60350599+david-mears-2@users.noreply.github.com>
Thu, 28 Nov 2024 13:47:55 +0000 (13:47 +0000)
committerGitHub <noreply@github.com>
Thu, 28 Nov 2024 13:47:55 +0000 (14:47 +0100)
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
Co-authored-by: Eduardo San Martin Morote <posva13@gmail.com>
packages/docs/ssr/nuxt.md

index 416a80313e64193caac1757b2e8eaf8020baa385..592ab0fca31d3a6a2c4fc800cf8e81cef7cf4ade 100644 (file)
@@ -64,18 +64,18 @@ await useAsyncData('user', () => store.fetchUser().then(() => true))
 
 ::: tip
 
-If you want to use a store outside of `setup()`, remember to pass the `pinia` object to `useStore()`. We added it to [the context](https://nuxtjs.org/docs/2.x/internals-glossary/context) so you have access to it in `asyncData()` and `fetch()`:
+If you want to use a store outside of `setup()` or an _injection aware_ context (e.g. Navigation guards, other stores, Nuxt Middlewares, etc), remember to pass the `pinia` instance to `useStore()`, for the reasons alluded to [here](https://pinia.vuejs.org/core-concepts/outside-component-usage.html#SSR-Apps). Retrieving the `pinia` instance might vary.
 
-```js
+```ts
 import { useStore } from '~/stores/myStore'
 
-export default {
-  asyncData({ $pinia }) {
-    const store = useStore($pinia)
-  },
-}
+// this line is usually inside a function that is able to retrieve
+// the pinia instance
+const store = useStore(pinia)
 ```
 
+Fortunately, most of the time you **don't need to go through this hassle**.
+
 :::
 
 ## Auto imports