6 Matching Annotations
  1. Mar 2021
    1. someGetter (state, getters, rootState, rootGetters) {

      Note including all the parameters here is important. If you do not include all four and you want to use rootGetters for example:

      someGetter (state, rootGetters) {

      rootGetters will be getters because getters is the second argument passed to this function and so you will not actually be on the root scope but instead the local scope.

      To access rootGetters in another name spaced module:

      someGetter (state, getters, rootState, rootGetters) {
        let value = rootGetters["module-name/getterName"](param1);
  2. Dec 2020
    1. Two-way Computed Property Admittedly, the above is quite a bit more verbose than v-model + local state, and we lose some of the useful features from v-model as well. An alternative approach is using a two-way computed property with a setter: <input v-model="message"> // ... computed: { message: { get () { return this.$store.state.obj.message }, set (value) { this.$store.commit('updateMessage', value) } } }

      Handling forms in vuex - use computed properties with a getter and a setter,

      the getter - pulls the value from the store the setter - commits the value to the store

    2. Components Can Still Have Local State Using Vuex doesn't mean you should put all the state in Vuex. Although putting more state into Vuex makes your state mutations more explicit and debuggable, sometimes it could also make the code more verbose and indirect. If a piece of state strictly belongs to a single component, it could be just fine leaving it as local state. You should weigh the trade-offs and make decisions that fit the development needs of your app.

      This is a common pattern I've seen with people adopting tools like [[redux]] or [[Vuex]] for [[state management]] without understanding the [[problems that state management tools aim to solve]]

      • [[Its ok to have local state]]
      • [[Not all state needs to be app state]]

      Not only does putting all of the state into the store cause extra indirection, it can make things complicated if you are putting in state that is tied to the lifecycle of a component - needing to clear / reset the state the next time it loads.

      It can also add complications when you have multiple instances of a component - and trying to make all of it's state got into Vuex - for example, if you had multiple carousel components on a screen - would there be value in trying to manage that state in vuex?

  3. Sep 2020
  4. Apr 2020
  5. Mar 2020
    1. Instead of mutating the state, actions commit mutations. Actions can contain arbitrary asynchronous operations.

      So for example an action may be a combination of mutation calls and async api calls.