用vue.js怎样写一个简易音乐播放器?
Admin 2021-09-13 群英技术资讯 1395 次浏览
 
                
                                怎样用vue.js写一个简易音乐播放器?很多朋友都比较喜欢听音乐,对于音乐播放器,最基础的功能就是可以切换歌曲,因此下文小编就给大家分享一个实现简易音乐播放器的实例,感兴趣的朋友可以参考。

运行效果如图所示:

代码如下:
<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8" />
  <title></title>
  <script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
  <style type="text/css">
   * {
    margin: 0;
    padding: ;
   }
   ul {
    list-style: none;
   }
   ul li {
    margin: 20px;
    padding: 10px 5px;
    border-radius: 3px;
   }
   ul li.active {
    background-color: aqua;
   }
      #control {
    width: 100%;
    height:80px;
   }
   .next,.before {
    width: 100px;
    height: 80px;
    background-color: aqua;
 
   }
   h1 {
       color: red
   }
   
  </style>
 </head>
 <body>
    <div id="app">
   
     <audio :src="currentSrc" controls="controls" autoplay="autoplay" @ended="changEnd"></audio>
       <h1>不仅仅是代码的搬运工</h1>
      <ul>
       <li :class='{active:index === currentIndex}' v-for='(item,index) in musicData' :key="item.id"     @click="changeSong(item.songSrc,index)">
     <h2>{{item.id }}---歌名:{{item.name}}----{{item.author}}</h2>
    </li>
      </ul>
   <div id="control">
    <button  class="before" type="button" @click="beforeSong" >上一首</button>
    <button  class="next" type="button" @click="nextSong" >下一首</button>
   </div>
   
     
    </div>
    <script type="text/javascript">
     const musicData = [{
          id: 1,
    name: '喜欢你',
    author: '陈洁仪',
    songSrc: './status/陈洁仪 - 喜欢你.mp3'
     },
     {
      id: 2,
      name: '我又想你了',
      author: '小鹅',
      songSrc: './status/小鹅 - 我又想你了.mp3'
     }
     ];
     var app = new Vue({
      el: '#app',
      data: {
       musicData,
       currentIndex: 0,
       currentSrc: './status/小鹅 - 我又想你了.mp3'
      },
      methods: {
       changeSong (src,index) {
        this.currentSrc = src;
        this.currentIndex = index;
       },
       changEnd () {
       this.currentIndex++;
       if(this.currentIndex===this.musicData.length){
      this.currentIndex = 0;
       }
       this.currentSrc = this.musicData[this.currentIndex].songSrc; 
       },
       nextSong () {
        this.currentIndex++;
        if(this.currentIndex===this.musicData.length){
          this.currentIndex = 0;
        }
         this.currentSrc = this.musicData[this.currentIndex].songSrc; 
        console.log(this.currentIndex)
       },
       beforeSong () {
        
        if(this.currentIndex===0){
         this.currentIndex=this.musicData.length; 
        }
         this.currentIndex--;
         this.currentSrc = this.musicData[this.currentIndex].songSrc; 
       }
       
       
      }
     })
    </script>
 </body>
</html>  
    以上就是关于vue.js实现简易音乐播放器的介绍,上述代码仅供参考,希望对大家学习和理解vue框架有帮助,想要了解更多vue.js实现音乐播放器的内容,可以继续浏览其他相关的文章。
文本转载自脚本之家
 
                
                                
                                免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要为大家详细介绍了vue自定义组件实现双向绑定,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
用for循环语句或filter()方法循环历数组,在每个循环中将一个数组元素分别去除2到sqrt(元素本身)。如果可以去除,则表明该组元素并非质数,而是质数。
在开发后台管理系统的时候,很多地方都要用到导出excel 表格,比如将table中的数据导出到本地,这篇文章主要给大家介绍了关于Vue导出Excel功能的相关资料,需要的朋友可以参考下
微信小程序实现评价功能 本文实例为大家分享了微信小程序实现评价的具体代码,供大家参考,具体内容如下 首先去图标库,找一个空心星图片和一个实星图片 先是效果图 代码 wxml文件 for循环5次,初始值是5星,data-name用于区别是那个评价的星星src="{{item-total+1>0?’…/image/empty_stars.png’:’…/image/entity_stars.png’}}"条件判断,图片判断一个是空星,一个实星,根据自己图片地址改变 <view class=& ...
cropper.js+exif.js怎样实现头像上传的基本编辑操作,一些朋友可能会遇到这方面的问题,对此在下文小编向大家来讲解一下,内容详细,易于理解,希望大家阅读完这篇能有收获哦,有需要的朋友就往下看吧!
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008