```js
// nuxt.config.js
-export default {
+export default defineNuxtConfig({
// ... other options
- buildModules: [
+ modules: [
// ...
'@pinia/nuxt',
],
-}
+})
```
And that's it, use your store as usual!
}
```
-## TypeScript
-
-If you are using TypeScript or have a `jsconfig.json`, you should also add the types for `context.pinia`:
-
-```json
-{
- "types": [
- // ...
- "@pinia/nuxt"
- ]
-}
-```
-
-This will also ensure you have autocompletion 😉 .
-
## Nuxt 2 without bridge
Pinia supports Nuxt 2 until `@pinia/nuxt` v0.2.1. Make sure to also install [`@nuxtjs/composition-api`](https://composition-api.nuxtjs.org/) alongside `pinia`:
}
```
+### TypeScript
+
+If you are using Nuxt 2 (`@pinia/nuxt` < 0.3.0) with TypeScript or have a `jsconfig.json`, you should also add the types for `context.pinia`:
+
+```json
+{
+ "types": [
+ // ...
+ "@pinia/nuxt"
+ ]
+}
+```
+
+This will also ensure you have autocompletion 😉 .
+
### Using Pinia alongside Vuex
It is recommended to **avoid using both Pinia and Vuex** but if you need to use both, you need to tell pinia to not disable it:
paths: [nuxt.options.rootDir, import.meta.url],
})
+ nuxt.hook('prepare:types', ({ references }) => {
+ references.push({ types: '@pinia/nuxt' })
+ })
+
// Add runtime plugin
if (isNuxt2()) {
addPlugin(resolver.resolve('./runtime/plugin.vue2'))