3.1视频播放:

  1. //取到id后利用循环取出url
  2. 在循环的模块中写入video标签
  3. <video controls class="video" :src="item.url"></video> //controls为控制,需要加上此属性,否则无法播放
  4. //vue中变量 需要在前加上“:”

3.2音频播放:

三目运算写好图片转换(播放按钮)

  1. <img :src="isPlay?require('../assets/pause.png'):require('../assets/play.png') "
  2. @click="handleImg"> //点击事件获取图片状态
  3. // require vue中获取静态资源
  4. <audio
  5. @play="onPlay"
  6. @pause="onPause"
  7. :src="playUrl" controls ref="audio">
  8. </audio> /*音频播放标签*/
  9. <script>
  10. export default {
  11. data() {
  12. return {
  13. isPlay:true, //设定isPlay状态选择播放按钮初始的图片
  14. playUrl:"https://music.163.com/song/media/outer/url?id=35625825" //音频地址Url
  15. }
  16. },
  17. methods: {
  18. handleImg(){
  19. this.isPlay=!this.isPlay
  20. if(this.isPlay){
  21. this.$refs.audio.pause() //音频暂停
  22. this.isPlay = true
  23. }else{
  24. this.$refs.audio.play() //音频播放
  25. this.isPlay = false
  26. }
  27. }, //事件函数,绑定图片状态给播放按钮
  28. onPlay(){
  29. this.isPlay = false
  30. },
  31. onPause(){
  32. this.isPlay = true //播放按钮回传状态给图片
  33. },
  34. getDom(){
  35. console.log(this.$refs.music); //获取Dom
  36. }
  37. },
  38. }
  39. </script>