Vue.js implements music player

Vue.js implements music player

This article shares the specific code of Vue.js to implement the music player for your reference. The specific content is as follows

The directory is as follows:

The running effect is shown in the figure:

The code is as follows:

<!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>More than just a code porter</h1>
      <ul>
       <li :class='{active:index === currentIndex}' v-for='(item,index) in musicData' :key="item.id" @click="changeSong(item.songSrc,index)">
     <h2>{{item.id }}---Song title: {{item.name}}----{{item.author}}</h2>
    </li>
      </ul>
   <div id="control">
    <button class="before" type="button" @click="beforeSong" >Previous song</button>
    <button class="next" type="button" @click="nextSong" >Next song</button>
   </div>
   
     
    </div>
    <script type="text/javascript">
     const musicData = [{
          id: 1,
    name: 'I like you',
    author: 'Kit Chan',
    songSrc: './status/Kit Chan- I Like You.mp3'
     },
     {
      id: 2,
      name: 'I miss you again',
      author: 'Little Goose',
      songSrc: './status/小鹅- I miss you again.mp3'
     }
     ];
     var app = new Vue({
      el: '#app',
      data: {
       musicData,
       currentIndex: 0,
       currentSrc: './status/小鹅- I miss you again.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>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • js to realize web music player
  • How to download music from Tik Tok at once using Python
  • Use Python web crawler to crawl the code of major music reviews
  • Playing background music in java
  • Make a music downloader with python
  • Android implements music video playback
  • A super cool music player made by myself in python

<<:  How to set static IP in CentOS7 on VirtualBox6 and what to note

>>:  MySQL 8.0.15 download and installation detailed tutorial is a must for novices!

Recommend

Method for realizing Internet interconnection by VMware virtual machine bridging

After installing VMware and creating a new virtua...

Tools to convert static websites into RSS

<br /> This article is translated from allwe...

Teach you how to write maintainable JS code

Table of contents What is maintainable code? Code...

Apache Bench stress testing tool implementation principle and usage analysis

1: Throughput (Requests per second) A quantitativ...

How to modify the default storage engine in MySQL

mysql storage engine: The MySQL server adopts a m...

Draw a heart with CSS3

Achieve resultsRequirements/Functionality: How to...

Detailed explanation of eight methods to achieve CSS page bottom fixed

When we are writing a page, we often encounter a ...

Analysis of MySQL multi-table joint query operation examples

This article describes the MySQL multi-table join...

How to modify the default network segment of Docker0 bridge in Docker

1. Background When the Docker service is started,...

Detailed explanation of the setting of background-image attribute in HTML

When it comes to pictures, the first thing we thi...

Lombok implementation JSR-269

Preface Introduction Lombok is a handy tool, just...

mysql method to recursively search for all child nodes of a menu node

background There is a requirement in the project ...

Share 8 MySQL pitfalls that you have to mention

MySQL is easy to install, fast and has rich funct...