Currently, I am developing a Vue2 component using vue-component that includes a subcomponent. Here is an example:
<note :bus="bus" :itemId="selectedId"></note>
The subcomponent contains the following code snippet:
<textarea v-model="text"></textarea>
In this setup, the subcomponent listens for events like this:
created() {
if (this.bus != null) {
this.bus.$on('store', () => {
this.store()
});
}
}
Meanwhile, the main component triggers events like so:
this.bus.$emit('store')
This causes the store function to be executed in all subcomponents. However, I have noticed that the store function is called multiple times after the initial trigger. This may be due to new subcomponents being created with each edit, or possibly because the registration with the bus needs to be handled differently.