The communication between Vue2.0 sibling components (or multilevel components) is better with Vuex or EventBus.

through vuex, it seems that you need to create an extra state variable, and then modify the state through component A, while component B listens for changes in the state, thus realizing the transmission of events. But it feels like the value of this state variable doesn"t really make sense (after all, it"s just the action itself that works), and it"s not intuitive to go around the vuex, a little more.

through EventBus, it feels more intuitive, but sometimes I need to know which components are listening after I throw an event, so I can only search the code for the event name globally, which is inconvenient for maintenance.

ask for advice, is there a better way to solve this problem?

Mar.03,2021

vuex is recommended.

  1. at the beginning of the project, I feel that there is less interaction between components, but I also use eventBus, but with more and more requirements and more and more communications, eventBus is not intuitive enough and is prone to errors. For example, if a business component is reused in four or five places and communicates with the parent and sibling components at the same time, it is easier to change the eventBus.
  2. vuex is simpler to use and has less impact on performance.
  3. write both demo, by yourself, contact me; the official project goes directly to vuex.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b311b8-2bd6e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b311b8-2bd6e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?