0👍
✅
Since this is a parent -> child communication, you can very simply use props:
- Store
blocks
on the parent component. - Pass
blocks
as a prop tobar
component. - Do any additional processing using computed properties.
- Display data using child’s template.
Here’s some guiding:
-
Define your component with props:
Vue.component('bar', { template: `<div class="bar">{{blocks.length}}</div>`, props: ['blocks'] });
-
Define
blocks
on the parent (in your example, the main vue component):new Vue ({ el: '#app', data: { blocks: [] }, methods: { add: function() { // do something with blocks } } });
-
Pass data down to the component:
<bar :blocks="blocks"></bar>
0👍
You can use the way which called “Event bus”
https://alligator.io/vuejs/global-event-bus/
Or you can create your own state management
https://v2.vuejs.org/v2/guide/state-management.html#Simple-State-Management-from-Scratch
But i highly recommend you too use vuex, since it will become hard to manage events and state when the project grows
Source:stackexchange.com