Just trying to get my head around Vuex / Nuxt , also quite new to nodejs.
Given that nuxt is a server side rendering app , Where does Vuex "reside" . In standard Vue , Vuex is a client side store. How does it work in Nuxt? Is it still a client side store but just rendered on the server first?
If it stays on the server , then I am just wondering how it handles per user data - or is it somehow shared. thank you.
In Vuex, our data store is defined as state in the store/index. js config object. Even though it sounds like new terminology to learn, think of it as the data property that we have been using this whole time.
The Vuex Store comes with Nuxt out of the box but is disabled by default. Creating an index. js file in this directory enables the store. This directory cannot be renamed without extra configuration.
import Vuex from "vuex"; import state from './state'; import actions from './actions'; import mutations from './mutations; export default { state, actions, mutations, }; There is no need to import the modules because Nuxt will do that for you.
A Typescript-ready Vuex plugin that enables you to save the state of your app to a persisted storage like Cookies or localStorage.
Both client and server hold the state. When the client makes the first request to load the initial page the state is usually passed through the html document inside a script, something like:
<script type="text/javascript" defer>window.__NUXT__={"data":[{"name":"server"}],"error":null,"serverRendered":true}</script>
Then when the application js load it has to pickup the state, this processed is known as rehydration. From this point the client will maintain the server state in sync.
Interesting parts of Nuxt documentation:
Nuxt Vuex Demo:
https://nuxtjs.org/examples/vuex-store
In addition take a look into vue ssr documentation, it's very detailed and it does a better job explaining how everything fits in:
we will serialize and inline the state in the HTML. The client-side store can directly pick up the inlined state before we mount the app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With