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!
Preface The MySQL permission table is loaded into...
Table of contents 1. Use plugin expressions 2. Us...
For Centos installation of MySQL, please refer to...
Preface: I believe that those who need to underst...
Table of contents Class Component Functional Comp...
What is DNS The full name of DNS is Domain Name S...
1. Why is eject not recommended? 1. What changes ...
This article shares with you how to use Vue to ch...
I will be learning MySQL next semester. I didn...
Table of contents JSON appears Json structure Jso...
The installation of the rpm package is relatively...
Payment countdown to return to the home page case...
Overview: The filesystem module is a simple wrapp...
In the previous article, we explained how nginx r...
Preface Last week, a colleague asked me: "Br...