[Vuejs]-Best event to save Vue.js appstate to localstorage

0👍

If you only have one component that mutates the data, and have only a handful of data points, then just use a watch for each data item that may change.

I’m not using Vuex as this is a simple application.

Vuex isn’t just for handling a large store. That said, I’ve avoided using Vuex in smaller application, because handling the store distributed throughout the app and components was acceptable. I can’t see the code or any details so YMMV, but… if you’re not keen on using Vuex, you could still implement some aspects that would help with this problem.

  1. Create a single store
    Having a unified location means that your various components reference your data, instead of storing it.
  2. Mutate state through a unified/consistent interface
    any change to the state should come through either the same function, or a consistent pattern. This way you can easily hook to the data changes, so you update your localStorage only when the data mutates.

You can implement this using custom Vue function, or a bus, but easiest to do it with vuex.

Leave a comment