[Vuejs]-Spotify Track Clone

0👍

You will need to use the Vue.js Custom event. And also you will need to accept an additional argument trackNum, so that the parent knows which track is been clicked. You code should change to something like this:

<track-display v-for="(track, index) in tracks" :track-title="TITLE" :artist="artist" :album="ALBUM" :trackNum="index"></track-display>

And when you emit the event you will need something like:

methods: {
  togglePlayState() { this.$emit('togglePlay', trackNum); },
}

The you will need to catch the event in parent and play the corresponding preview-url in the tracks array, since the trackNum is corresponding to the position in tracks.

Leave a comment