绑定一个点击事件

  1. <div class="container" @click="handleclick(data.id)"> // 获取id

在methods里面写

  1. methods:{
  2. handleclick(id){
  3. console.log(id)
  4. this.$router.push(`/detail?id=${id}`)
  5. }
  6. }

在详情页接收子组件的传值
export default

  1. computed:{
  2. id(){
  3. return this.$route.query.id
  4. }
  5. }

http 请求

  1. mounted(){
  2. this.axios.get(`playlist/detail?id=${this.id}`).then(res=>{
  3. this.tracks = res.data.playlist.tracks;
  4. console.log(this.tracks)
  5. })
  6. }

传多个参数

  1. <div class="container" @click="handleclick(data.id,data.name)">
  2. methods:{
  3. handleclick(id,name){
  4. this.$router.push(`/details?id=${id}&name=${name}`)
  5. }
  6. }
  7. computed:{
  8. id(){
  9. return this.$route.query.id
  10. },
  11. name(){
  12. return this.$route.query.name
  13. }
  14. }
  15. mounted(){
  16. this.axios.get(`mv/url?id=${this.id}`).then(res=>{
  17. this.url=res.data.data.url;
  18. })
  19. }