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

In-depth explanation of MySQL user account management and permission management

Preface The MySQL permission table is loaded into...

The difference between Vue interpolation expression and v-text directive

Table of contents 1. Use plugin expressions 2. Us...

How to install and modify the initial password of mysql5.7.18

For Centos installation of MySQL, please refer to...

Detailed explanation of the use of props in React's three major attributes

Table of contents Class Component Functional Comp...

Linux Domain Name Service DNS Configuration Method

What is DNS The full name of DNS is Domain Name S...

How to modify create-react-app's configuration without using eject

1. Why is eject not recommended? 1. What changes ...

Vue implements a shopping cart that can change the shopping quantity

This article shares with you how to use Vue to ch...

MySQL 8.0.19 installation and configuration tutorial under Windows 10

I will be learning MySQL next semester. I didn...

Understanding JSON (JavaScript Object Notation) in one article

Table of contents JSON appears Json structure Jso...

Nginx source code compilation and installation process record

The installation of the rpm package is relatively...

js to realize payment countdown and return to the home page

Payment countdown to return to the home page case...

Detailed explanation of fs module and Path module methods in Node.js

Overview: The filesystem module is a simple wrapp...

Detailed explanation of nginx request header data reading process

In the previous article, we explained how nginx r...

The difference between delete, truncate, and drop and how to choose

Preface Last week, a colleague asked me: "Br...