Let's say I have the following component hierarchy:
App.vue
- vue-router's
router-view
tagHome.vue
: the home pagePopularAudioList.vue
About.vue
some static page
Player.vue
: an always-on-top audio player that can be used throughout the site. Playback isn't interrupted when switching pages. It has visible play/stop/volume controls.
- vue-router's
PopularAudioList.vue
renders a list of audio files that users can choose from, and a play button for each item. Each play button emits a audio-file-chosen
event with a URL parameter. I know how to make the component's parent, Home.vue
, hook in to this event. But I'd like Player.vue
to catch it, since that's the component that will be controlling audio playback.
What's the best way to propagate the event there? I could try to make Home.vue
re-emit the event to App.vue
, which would need to pass it to Player.vue
. But that seems horribly inefficient, it smells like bad architecture, and vue-router might make this difficult.
Should I reorganize my architecture to create a more direct relation between PopularAudioList.vue
and Player.vue
to make this work? Are events even the right choice here?