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!
Table of contents Create a new user Authorize new...
1. Dynamic query rules The dynamic query rules ar...
1. What is master-slave replication? The DDL and ...
Table of contents 1. Block scope 1.1. let replace...
This article analyzes the consistency processing ...
Method 1: float:right In addition, floating will ...
Preface I believe that the syntax of MySQL is not...
Preface This article mainly summarizes some of th...
Table of contents Installation-free version of My...
Implementation ideas First, create a parent conta...
Phenomenon Start the Docker container docker run ...
Table of contents 1. Operators Summarize 1. Opera...
Table of contents plan Install Dependencies Intro...
0. Environment Operating system for this article:...
1. Nexus configuration 1. Create a docker proxy U...