The most serious question of Vue is the bug of communication between non-parent and child components.

1. There are three components
-1-ordering component
-2-ordered component
-3-button component (button for adding meals)
2. Logic function
-1-Click the add button in the ordering component to display
3 in the click. There is a code
-1-order component:

clipboard.png

:

clipboard.png

-2- :

clipboard.png

-3- :

clipboard.png

4. Question:
each meal needs to be clicked twice to be displayed in the ordered component.

5. Personal analysis:
when there is no click to add event, the count of the meal is not available at first, so passing it to the button component is actually empty; when you click the add button, add 1 to the count of the meal, the calculation attribute judgment in the ordering component will be passed, and only in this way will it be displayed; every meal is like this

6. If the value is passed directly to the selected component, and if it has been selected as a sub-component of the selected meal, it is fine; but now the problem is that the two are not father-son relationship, but sibling relationship. Try to pass eventbus, but it still does not work. When eventbus is a page created, it will only be executed once

.

7. Ask how to solve the problem.

Mar.04,2021

Wah Su University Primary School Girl, I think you should give up using vuex for Bus,. In this case, just put all the data in store. You don't need to deal with so many events. You just need to care about how to modify the data. You can get the commodity data directly in other components, and you don't need to notify other components through events.

Menu