vuex-module-decorators | ES7 Decorators to create Vuex modules | State Container library
kandi X-RAY | vuex-module-decorators Summary
kandi X-RAY | vuex-module-decorators Summary
TypeScript/ES7 Decorators to create Vuex modules declaratively
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of vuex-module-decorators
vuex-module-decorators Key Features
vuex-module-decorators Examples and Code Snippets
Community Discussions
Trending Discussions on vuex-module-decorators
QUESTION
Below Nuxt middleware
...ANSWER
Answered 2021-Oct-04 at 13:02This is one of the main challenges when working with SSR. So there's a process called Hydration that happens on the client after receiving the response with static HTML from the server. (you could read more on this Vue SSR guide)
Because of the way Nuxt is built and how the SSR/Client relationship works for hydration, what might happen is your server rendering an snapshot of your app, but the async data not being available before the client mounts the app, causing it to render a different store state, breaking the hydration.
The fact frameworks like Nuxt and Next (for React) implement their own components for Auth, and many others, is to deal with the manual conciliation process for correct hydration.
So going deeper on how to fix that without using Nuxt built-in auth module, there are a few things you could be aware of:
- There the
serverPrefetch
method, that will be called on the Server-side which will wait until the promise is resolved before sending to the client to render it - Besides the component rendering, there's the context sent by the server to the client, which can be injected using the
rendered
hook, that's called when the app finishes the rendering, so the right moment to send your store state back to the client to reuse it during hydration process - On the store itself, if you're using
registerModule
, it supports an attributepreserveState
, that's responsible for keeping the state injected by the server.
For the examples on how to work those parts, you could check the code on this page
Last, more related to your user auth challenge, another option would be to use nuxtServerInit
on store actions to run this auth processing, since it'll be passed directly to the client afterwards, as described on Nuxt docs.
On the same page, the docs present that the first argument on the nextServerInit is the context
, meaning you could get the store
, for instance, from there.
Also one important point to mention, is that on your original question, you've mentioned that you don't want 3rd party libs, but you're already using one that brings a lot of complexity to the table, namely the nuxt-property-decorator
.
So not only you're dealing with SSR that's as complicated as it gets when using frameworks, but you're not using pure Vue, but Next, and not using pure TS Nuxt, but adding another complexity with decorators for the store.
Why am I mentioning it? Because taking a quick look on the lib issues, there are other people with the same issue of not accessing the this
correctly.
Coming from a background of someone that used both Nuxt (Vue) and Next (React), my suggestion with you is to try to reduce the complexity, before trying out a lot of different stuff.
So I'd test running your app without this nuxt-property-decorator
to check if this works with the out-of-the-box store implementation, ensuring it's not a bug caused on the lib not fully prepared to support SSR complexity.
QUESTION
I cannot find an answer to this question anywhere.
I went through the official Nuxt documentation and through the existing Stack Overflow and Github issue discussions.
Implementation of the AuthModule:
...ANSWER
Answered 2021-Sep-28 at 20:00After some trial and error I finally discovered the answer to my question.
If you are like me; only starting your journey with Vue, Nuxt & vuex-module-decorators and you get stuck tackling this exact same problem, I hope this little solo QA ping-pong finds you well!
My solution looks like this:
QUESTION
I have async function named save in a my component
...ANSWER
Answered 2021-Jun-10 at 19:25I'm new to javascript and typescript and frontend frameworks .
After many attempts for this problem in stackoverflow an also reading the docs ,I found nothing so i decided to do more debugging and i understand Vuex actions only take one arguments so another arguments values becomes undefined
QUESTION
I am trying to setup a vue3 app with i18n localization. The localization is supposed to be located in json files. I added i18n via vue add i18n
to my project. The questions asked during installation were all answered with the default value except the one with the legacy support (my answer: no). When i try to use a text from a json file, it will tell me in the console [intlify] Not found 'message' key in 'en' locale messages.
The local translations work just fine.
And i have no clue why it is not working with the translations provided in the JSON file.
Here is my code:
packages.json
...ANSWER
Answered 2021-Jun-08 at 15:27The main probles is that the function in i18n.ts doing loadLocalMessages is not getting properly the files from the locales folder.
QUESTION
I have 1 app using the vue pwa plugin, it works great.
The vuejs config for the app looks like this:
...ANSWER
Answered 2021-Mar-26 at 11:26You are not having dev/sw.js
in your project, as you set in swSrc
. InjectManifest
means take this sw.js
source file and write precache manifest into it, producing the final service-worker.js
file.
QUESTION
I am using nuxtjs with typescript and use vuex-module-decorators. but I get error when add @nuxtjs/auth
to my project.
Uncaught (in promise) Error: ERR_STORE_NOT_PROVIDED: To use getModule(), either the module should be decorated with store in decorator, i.e. @Module({store: store}) or store should be passed when calling getModule(), i.e. getModule(MyModule, this.$store)
This error happen when call Action.
When @nuxtjs/auth
from modules it's ok.
store/index.ts
...ANSWER
Answered 2020-Aug-14 at 15:46I add vuex: false
to auth
in nuxt.config.js
add error gone, but now I do not access to to $auth.user
in components. So I do it by my self and create user store in vuex and manually get user info.
QUESTION
I'm currently learning Vue, Vuex and TypeScript and I must say I'm kinda confused about how to setup a Vuex store correctly. The documentation doesn't cover a TypeScript implementation at all (I have the feeling that documentation in general lacks fundamental TypeScript examples?) what made me (again!) look for solutions on other pages outside the official documentation (which imho shouldn't happen if a new technology is learned directly via the official resources as it should contain all the information necessary to get the technology working, right?!).
So when I looked in the world wide web for solutions, I came across the following patterns:
On bezkoder.com they use decorators from
vuex-module-decorators
to define the Vuex store modules as classes. Then, they use decorators again, but this time fromvuex-class
, to access the respective states, mutations and actions from their Vue components. This solution seems to be very "TypeScripty" as they make use of classes and decorators like in the official Vue TypeScript documentation.On itnext.io (a Medium.com site) they use a so called "direct store" with
direct-vuex
. Here, they define the store itself in a more "JavaScripty" way, as all the states, mutations and actions are passed to the store instance as plain objects.On dev.to and codeburst.io (another Medium.com site) they use plain TypeScript features to create their store. They therefore setup a lot of constants
enums
andstrings
and define severalinterfaces
in a bunch of different files which are then all exported and imported again to index file of each module which then creates the respective Vuex module. This solution is somehow a mix of a "TypeScripty" and "JavaScripty" solution. It seems like that this method creates the most boilerplate code.
So now, as a Vue beginner, I'm kinda confused and I have the following questions:
- Which method (1, 2 or 3 or is there maybe another one?) should I prefer and why? What are the advantages and the disadvantages of these methods? (I searched for a comparison of the different approaches but I couldn't find anything.)
- Should I use plugins which aren't maintained by the official Vue team? How can I be sure that these plugins will get updated to work with future Vue releases? (For example in the GitHub repo from
vuex-module-decorators
the author explicitly says, that the plugin is just a side project of him what makes me doubt that the plugin will get long term updates.) - Why isn't there anything about that in the official documentation? Why is the official documentation lacking so much TypeScript examples? Is there a place where I can find reliable TypeScript example and solutions to the must common scenarios?
ANSWER
Answered 2020-Sep-21 at 18:25i'm not allowed to comment, so i need to answer, but i also can't answer all your questions... I was in a similar situation. And am now using vuex-module-decorators. This feels, as you wrote, very typescipty and the setup was rather simple, the usage is so too.
As I have to update my code quite often and eventually update Vue.js etc... I took the risk to use this (big) dependency, knowing that i maybe have to rebuilt my stuff at some point. But using vuex-module-decorators safed me alot of time and almost never got me any problems. I don't know the other solutions but this feels to me very natural to vue and typescript.
I hope the will help
Best regards
QUESTION
I'm using vuex-module-decorators
and I would like to know if I should set the default value of a data property to null
or undefined
. Example:
ANSWER
Answered 2020-Aug-14 at 07:51If state value cannot be determined, it MUST be initialized with null. Just like wheels: number | null = null.
From the docs.
QUESTION
I am using vue-prop-decorator and Quasar Framework. I have a component, in which I recieve a prop, defined as follow:
...ANSWER
Answered 2020-Jul-14 at 12:06Today I found the problem. Vue itself does not explain so much about what Is happening in the warning message.
Nevertheless, as you can see in the Prop definition, it expects a Fabricante instance, and I was sending just a raw object from a request. Creating a class like
QUESTION
I am currently trying to retrieve the tags
in the Searchbar module from Vuex. However, it is not reactive.
Here is the component :
...ANSWER
Answered 2020-Jun-04 at 14:50Ok I found the problem. My bad : it has nothing to do with the composition API. The above code is working concerning it.
In the Vuex module, I had to update the addTag
mutation as follow :
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install vuex-module-decorators
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page