Vuex overview

Ways to share data between components

The parent passes the value to the child: v-bind property binding The
child passes the value to the parent: v-on property binding The
data is shared between sibling components: EventBus

  • $on the component that receives the data
  • $emit the component that sent the data

What is Vuex

Vuex is a mechanism for realizing the global state (data) management of components, which can easily realize the sharing of data between components. A
Insert picture description here
brief explanation:

Vuex stipulates that the state belonging to the application level can only be modified by methods in Mutation, and the dispatch of events in Mutation can only be done through actions.

From left to right, starting from the component, the component calls the action. At the action level, we can interact with the background data, such as obtaining the initialized data source, or filtering the intermediate data. Then dispatch Mutation in the action. Mutation to trigger the change of state, the change of state will trigger the update of the view.

Precautions

The data flow is one-way. The
component can call action
actions to dispatch
mutations. Only mutations can change the state. The
store is responsive. Whenever the state is updated, the components will be updated synchronously.


Vuex uses centralized storage to manage the state of all components of the application, and uses corresponding rules to ensure that the state changes in a predictable manner. He can easily realize data sharing between components
Insert picture description here

Benefits of using Vuex to manage state uniformly

  • Ability to centrally manage shared data in Vue, easy to develop and maintain
  • Able to efficiently realize data sharing between components and improve development efficiency
  • The data stored in vuex is responsive and can keep the data and page synchronized in real time

What kind of data is suitable for storing in Vuex?

In general, only the data shared between components need to be stored in Vuex;
for the private data in the component, it can still be stored in the data of the component itself.

Self-motivation

On the road to success, there will definitely be failures; for failure, we must treat and treat it correctly. If you are not afraid of failure, you will succeed; if you are afraid of failure, you will be worthless, and you will fail.

Commitment to pigs

The boyfriend can’t make the girlfriend angry. The girlfriend is angry because the boyfriend is wrong. In any case, the boyfriend is wrong. If the boyfriend is wrong, he must willingly accept any punishment from the girlfriend, otherwise he will be matched with the girlfriend boyfriend. Just spit on Han, the boyfriend should make his girlfriend more happy and think more about his girlfriend, know how to pity and cherish his girlfriend, and take care of his girlfriend. To be continued. . . .

Guess you like

Origin blog.csdn.net/weixin_50001396/article/details/114222361