vuex - is it possible to directly change state, even if not recommended?

前端 未结 2 1502
伪装坚强ぢ
伪装坚强ぢ 2020-12-06 02:10

The documentation at https://vuex.vuejs.org/en/getting-started.html says,

You cannot directly mutate the store\'s state. The only way to change a sto

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 02:45

    I am going to make this very simple:

    Because the state object is already reactive, you can completely avoid using getters and mutations. All of Vue’s templates, computed, watch, etc. will continue to work the same as if using a component’s data. The store’s state acts as a shared data object.

    But by doing so you will lose the ability to implement time-travel debugging, undo/redo, and setting breakpoints, because you will have circumvented the command design pattern and encapsulation of a member by using methods. https://en.m.wikipedia.org/wiki/Command_pattern

提交回复
热议问题