I'm working on a SPA website and I'm trying to pass some data between two components using a router-link.
Basically I have an "Album" component (here called Polaroid) which contains in its 'data' all the album songs' lyrics. Then I have a Song component (here called Canzone) where I want to pass dynamically the lyrics for each song, based on the clicked song obviously.
This is my code:
routes.js
import Polaroid from './components/albums/Polaroid'
import Canzone from './components/songs/Canzone.vue'
export default {
mode: 'history',
linkActiveClass: 'font-bold',
routes: [
{
path: '/polaroid',
component: Polaroid
},
{
path: '/polaroid/:canzone',
name: 'polaroid',
component: Canzone
},
]
};
Polaroid.vue (this is the Album component where I show the songs' list)
<template>
<div>
<ul class="leading-7">
<li v-for="canzone in this.canzoni" :key="canzone.nome" >
<router-link :to="{ name: 'polaroid', params: { name: canzone.path } }"> {{ canzone.nome }} </router-link>
</li>
</ul>
</div>
</template>
<script>
export default {
data(){
return {
canzoni: [ // all the songs
{
nome: 'Song1',
path: 'song-1',
numero: 1,
testo: 'lyrics1'
},
{
nome: 'Song2',
path: 'song2',
numero: 2,
testo: 'lyrics2'
},
{
nome: 'Song3',
path: 'song3',
numero: 3,
testo: 'lyrics3'
},
],
};
},
}
</script>
Canzone.vue (this is the Song component where I want to show the song lyric dinamically)
<template>
<div>
LYRICS HERE
{{ $route.params.canzone }} // not working
</div>
</template>
<script>
export default {
}
</script>
How can I pass the data through the router-link? Thanks!
Thanks!
this.in v-for