绑定一个点击事件
<div class="container" @click="handleclick(data.id)"> // 获取id
在methods里面写
methods:{
handleclick(id){
console.log(id)
this.$router.push(`/detail?id=${id}`)
}
}
在详情页接收子组件的传值
export default
computed:{
id(){
return this.$route.query.id
}
}
http 请求
mounted(){
this.axios.get(`playlist/detail?id=${this.id}`).then(res=>{
this.tracks = res.data.playlist.tracks;
console.log(this.tracks)
})
}
传多个参数
<div class="container" @click="handleclick(data.id,data.name)">
methods:{
handleclick(id,name){
this.$router.push(`/details?id=${id}&name=${name}`)
}
}
computed:{
id(){
return this.$route.query.id
},
name(){
return this.$route.query.name
}
}
mounted(){
this.axios.get(`mv/url?id=${this.id}`).then(res=>{
this.url=res.data.data.url;
})
}