Skip to content

Commit

Permalink
refactor(nuxt): use object syntax for nuxt 3 plugin (#2588)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Huang <[email protected]>
  • Loading branch information
huang-julien and Julien Huang authored Feb 23, 2024
1 parent eb420ee commit e90ec25
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions packages/nuxt/src/runtime/plugin.vue3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ import { createPinia, setActivePinia } from 'pinia'
import type { Pinia } from 'pinia'
import { defineNuxtPlugin, Plugin } from '#app'

const plugin: Plugin<{ pinia: Pinia }> = defineNuxtPlugin((nuxtApp) => {
const pinia = createPinia()
nuxtApp.vueApp.use(pinia)
setActivePinia(pinia)
const plugin: Plugin<{ pinia: Pinia }> = defineNuxtPlugin({
name: 'pinia',
setup(nuxtApp) {
const pinia = createPinia()
nuxtApp.vueApp.use(pinia)
setActivePinia(pinia)

if (process.server) {
nuxtApp.payload.pinia = pinia.state.value
} else if (nuxtApp.payload && nuxtApp.payload.pinia) {
pinia.state.value = nuxtApp.payload.pinia
}
if (process.server) {
nuxtApp.payload.pinia = pinia.state.value
} else if (nuxtApp.payload && nuxtApp.payload.pinia) {
pinia.state.value = nuxtApp.payload.pinia
}

// Inject $pinia
return {
provide: {
pinia,
},
// Inject $pinia
return {
provide: {
pinia,
},
}
}
})

Expand Down

0 comments on commit e90ec25

Please sign in to comment.