2.gif

    1. <audio @play="onPlay"
    2. @pause="onPause"
    3. :src="playUrl" controls ref="audio"></audio>
    1. <script>
    2. export default {
    3. name:"audio",
    4. data(){
    5. return{
    6. isPlay:false,
    7. playUrl:"https://music.163.com/song/media/outer/url?id=35625825"
    8. }
    9. },
    10. methods:{
    11. handle(){
    12. if(this.isPlay){
    13. this.$refs.audio.pause()
    14. this.isPlay = false
    15. }else{
    16. this.$refs.audio.play()
    17. this.isPlay = true
    18. }
    19. },
    20. onPlay(){
    21. this.isPlay = true
    22. },
    23. onPause(){
    24. this.isPlay = false
    25. },
    26. getDom(){
    27. console.log(this.$refs.music)
    28. }
    29. }
    30. }
    31. </script>