You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So in the docs, you can import stores outside a component and create helpers outside of the setup method. How would someone use useMutation for example, in a Nuxt plugin?
Say you have a plugin/sample.ts
import{namespacedHelpers}from'~/store/auth';const{ useMutations }=namespacedHelpers;const{ setIsAuthenticated}=useMutations();exportdefaultdefineNuxtPlugin((context)=>{// use setIsAuthenticated here})
This throws an error: You must use this function within the "setup()" method, or insert the store as first argument. which is reasonable because it's outside the setup() method.
But what's the line saying or insert the store as first argument? I don't have a store variable that I can pass because Nuxt treats files as modules and it only exports states, mutations, getters and actions.
The text was updated successfully, but these errors were encountered:
Nuxt has a very strict behavior and trying to break that behavior will cause server memory leaks (from experience).
I believe you can use a nuxt-middleware to get the store, but be careful with that solution.
So in the docs, you can import stores outside a component and create helpers outside of the setup method. How would someone use
useMutation
for example, in a Nuxt plugin?Say you have a
plugin/sample.ts
and
store/auth.ts
This throws an error:
You must use this function within the "setup()" method, or insert the store as first argument.
which is reasonable because it's outside thesetup()
method.But what's the line saying
or insert the store as first argument
? I don't have a store variable that I can pass because Nuxt treats files as modules and it only exports states, mutations, getters and actions.The text was updated successfully, but these errors were encountered: