Use Pinia with Nuxt and composition-api (vue2) and SSR #574
-
I can use Pinia with Nuxt, without SSR: import { defineStore } from 'pinia'
export const useInvitesStore = defineStore({
id: 'storeId',
state() {
return {
invites: [],
loading: true,
}
},
}) <script>
import { useInvitesStore } from '@/store/invitesStore'
import { onMounted, useFetch, useContext, defineComponent } from '@nuxtjs/composition-api'
export default defineComponent({
setup() {
const { $axios, pinia } = useContext()
const invitesStore = useInvitesStore(pinia)
onMounted(() => {
invitesStore.loading = true
$axios.$get('invite/registermember').then((result) => {
invitesStore.loading = false
invitesStore.invites = result.invites
})
})
// !!! If I uncomment this empty useFetch, I get the error: Converting circular structure to JSON
// useFetch(async () => {
// })
return {
invitesStore,
}
},
})
</script> But, as soon as I uncomment the Am I doing anything wrong here? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Only from the code sample I can't tell. Did you manage to fix this or reproduce in a bare bones project? BTW You shouldn't pass the |
Beta Was this translation helpful? Give feedback.
-
It seems like |
Beta Was this translation helpful? Give feedback.
-
Hi @posva , regarding nuxt with pinia, is there an equivalent of |
Beta Was this translation helpful? Give feedback.
It seems like
$nuxt
being enumerable was a problem. It should be fixed in 0.5.4!