audio-card.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <div style="width: 640px">
  3. <v-card
  4. color="white"
  5. >
  6. <v-card-title>
  7. <!-- <v-avatar>
  8. <img
  9. :src="item.avatarUrl"
  10. alt="social"
  11. >
  12. </v-avatar>-->
  13. <span class="text-body-1 font-weight-light">{{ item.userId }}</span>
  14. <span class="text-body-1 font-weight-light">{{ item.pubDate }}</span>
  15. </v-card-title>
  16. <v-card-text class-name="text-h5 font-weight-bold">
  17. <span v-html="item.title" />
  18. <div>
  19. <audio-player
  20. ref="audioPlayer"
  21. :show-prev-button="false"
  22. :show-next-button="false"
  23. :show-playback-rate="false"
  24. :audio-list="audioList.map(elm => elm.url)"
  25. :before-play="handleBeforePlay"
  26. theme-color="#87CEFA"
  27. />
  28. </div>
  29. </v-card-text>
  30. <v-icon
  31. small
  32. left
  33. >
  34. mdi-twitter
  35. </v-icon>
  36. </v-card>
  37. </div>
  38. </template>
  39. <script>
  40. export default {
  41. name: 'AudioCard',
  42. props: {
  43. item: {
  44. type: Object,
  45. default: () => {
  46. }
  47. }
  48. },
  49. data() {
  50. return {
  51. currentAudioName: '',
  52. audioList: []
  53. }
  54. },
  55. created() {
  56. this.audioList = [
  57. { name: this.item.title, url: this.item.audioUrl }
  58. ]
  59. },
  60. methods: {
  61. // 播放前做的事
  62. handleBeforePlay(next) {
  63. // 这里可以做一些事情...
  64. this.currentAudioName = this.audioList[this.$refs.audioPlayer.currentPlayIndex].name
  65. next() // 开始播放
  66. },
  67. handlePlaySpecify() {
  68. this.$refs.audioPlayer.currentPlayIndex = 1
  69. this.$nextTick(() => {
  70. this.$refs.audioPlayer.play()
  71. this.title = this.audioList[
  72. this.$refs.audioPlayer.currentPlayIndex
  73. ].name
  74. })
  75. }
  76. }
  77. }
  78. </script>
  79. <style>
  80. </style>