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:
|
<<: 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!
After installing VMware and creating a new virtua...
<br /> This article is translated from allwe...
Table of contents What is maintainable code? Code...
1: Throughput (Requests per second) A quantitativ...
mysql storage engine: The MySQL server adopts a m...
Table of contents 1. Add monitoring Linux host 2....
MySQL Bin log data recovery: accidentally delete ...
Achieve resultsRequirements/Functionality: How to...
When we are writing a page, we often encounter a ...
This article describes the MySQL multi-table join...
1. Background When the Docker service is started,...
When it comes to pictures, the first thing we thi...
Preface Introduction Lombok is a handy tool, just...
background There is a requirement in the project ...
MySQL is easy to install, fast and has rich funct...