Search code examples
javascriptvue.jsvuex

Is it necessary to use Vuex for a Vue-based shopping cart?


I want to let two separate Vue components communicate with each other (not siblings, so not child or parent).

Let's assume I have a Laravel blade template file like that:

<div id="app">
  <div class="header">
     <shopping-cart></shopping-cart>
  </div>
  <div class="content">
     <products-list></products-list>
   </div>
</div>

How can I send a product from component to component (putting products to the cart) ?


Solution

  • If you want to get the right solution with the right structure, and it's simple, you have to use the State Manager(Vuex), because it's the best solution. I wanted to write this in the comment, but I could not because I did not have enough reputation.