I have an audio player component that needs to send a message to all other players to pause themselves when it is clicked. However, there's a variable amount of components all inside of a v-for loop. It looks something like this:
<template>
<AudioPlayer v-for="song in songs" :key="song.id" @play="pauseOthers" />
</template>
<script>
import { defineComponent, ref } from 'vue';
import AudioPlayer from '@/components/AudioPlayer.vue';
export default defineComponent({
setup(){
var songs = [{id: "song1"},{id: "song2"}]
const pauseOthers = () => {
//this is the part that I need to figure out
}
return { songs, pauseOthers }
}
})
</script>
The components's script looks like
<script>
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup(){
const pause = () => {
console.log("Paused!");
}
return { pause }
}
})
</script>
Ideally this could avoid using third-party packages, but it's fine if there really is no easy way.