1. <template>
    2. <div>
    3. <audio
    4. @pause="onPause"
    5. @play="onPlay"
    6. ref="audio"
    7. class="audio" :src="playUrl" controls autoplay loop>你的浏览器不支持audio标签</audio>
    8. <img :src="isPlay?require('@/assets/images/play.png'):require('@/assets/images/pause.png')" @click="toggle">
    9. </div>
    10. </template>
    1. <script>
    2. export default {
    3. name: "Mv",
    4. data(){
    5. return {
    6. isPlay:false,
    7. playUrl:"http://m10.music.126.net/20191112163035/75b7eecc4d98e245c93645fd1810ba3d/ymusic/e54a/90bc/8f90/29b0d3a279414b2f9a1fd78c64a907cc.mp3"
    8. }
    9. },
    10. methods:{
    11. toggle(){
    12. return this.isPlay? this.pause():this.play()
    13. },
    14. play(){
    15. this.$refs.audio.play()
    16. },
    17. pause(){
    18. this.$refs.audio.pause()
    19. },
    20. // 当音频播放
    21. onPlay () {
    22. this.isPlay = true
    23. console.log(this.isPlay)
    24. },
    25. // 当音频暂停
    26. onPause () {
    27. this.isPlay = false
    28. }
    29. }
    30. };
    31. </script>