<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>音乐播放器</title>
</head>
<body>
<div id="player">
<input type="text" v-model="query" @keyup.enter="searchMusic">
<hr>
<ul>
<li v-for="item in musicList">
<a href="javascript:;" @click="playMusic(item.id)">
<b>{{item.name}}</b>
</a>
</li>
</ul>
<hr>
<div>
<audio ref='audio' :src="musicUrl" controls autoplay loop></audio>
</div>
<div>
<img :src="musicImg" style="width: 200px;height: 200px" v-show="musicImg!=''" />
</div>
<table style="border:1px solid #0094ff;">
<tr>
<th>头像</th>
<th>昵称</th>
<th>评论</th>
<th>点赞</th>
</tr>
<tr v-for="comment in commentList">
<td>
<img :src="comment.user.avatarUrl" style="width: 50px;height: 50px">
</td>
<td v-text="comment.user.nickname"></td>
<td v-text="comment.content"></td>
<td v-text="comment.likedCount"></td>
</tr>
</table>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/axios@0.21.1/dist/axios.min.js"></script>
<script>
var app = new Vue({
el: '#player',
data: {
query: '',
musicList: [],
musicUrl: '',
musicImg: '',
commentList: []
},
methods: {
searchMusic: function () {
var that = this;
axios.get('https://autumnfish.cn/search?keywords=' + this.query)
.then(function (response) {
console.log(response.data.result.songs);
that.musicList = response.data.result.songs;
}, function (err) {
console.log(err);
})
},
playMusic: function (musicId) {
var that = this;
console.log(musicId);
axios.get('https://autumnfish.cn/song/url?id=' + musicId)
.then(function (response) {
console.log(response.data.data[0].url);
that.musicUrl = response.data.data[0].url;
}, function (err) {
console.log(err);
})
axios.get('https://autumnfish.cn/song/detail?ids=' + musicId)
.then(function (response) {
console.log(response.data.songs[0].al.picUrl);
that.musicImg = response.data.songs[0].al.picUrl;
}, function (err) {
console.log(err);
})
axios.get('https://autumnfish.cn/comment/hot?type=0&id=' + musicId)
.then(function (response) {
console.log(response.data.hotComments);
that.commentList = response.data.hotComments;
}, function (err) {
console.log(err);
})
}
}
})
</script>
</body>
</html>