vue基础篇 04 综合应用

12 篇文章 0 订阅

04 综合应用

实战演练

音乐播放器

代码
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>音乐播放器</title>
		<style type="text/css">
			ul{
				float: left;
				height: 1000px;
				width: 350px;
				overflow: auto;
			}
			li{
				list-style: none;
				height: 30px;
				width: 350px;
			}
			audio{
				float: left;
			}
			span{
				font-size: 10px;
			}
		</style>
	</head>
	<body>
		<div id="app">
			<input type="text" 
			v-model="inputValue" 
			@focus="inputFuncus()"
			@blur="inputBlur()"
			@keyup.enter="searchKeyWord(inputValue)"/>
			<br>
			<audio :src="songUrl" autoplay="autoplay" controls="controls"></audio>
			<br>
			<ul>
				<li v-for="item in songs">
					<a href="#" @click="searchSongId(item.id)">
						{{item.name}}
					</a>
					<span>-{{item.artists[0].name}}</span>
					&nbsp;&nbsp;
					<span>{{item.alias[0]}}</span>
					&nbsp;&nbsp;
					<a href="#" v-show="item.mvid!=0" @click="searchMVId(item.mvid)">
						mv
					</a>
				</li>
			</ul>
			<div v-show="isShow">
				<video :src="mvUrl" controls="controls" autoplay="autoplay">
				</video>
			</div>
		</div>
		<!-- axios -->
		<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
		<!-- 开发环境版本,包含了有帮助的命令行警告 -->
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
		<script type="text/javascript">
			var app=new Vue({
				el:'#app',
				data:{
					inputValue:'歌名、歌手',
					songs:[],
					songUrl:'',
					mvUrl:'',
					isShow:false
				},
				methods:{
					inputFuncus:function(){
						if(this.inputValue=='歌名、歌手'){
							this.inputValue='';
						}
					},
					inputBlur:function(){
						if(this.inputValue==''){
							this.inputValue='歌名、歌手';
						}
					},
					searchKeyWord:function(keyWord){
						var that=this;
						axios.get('https://autumnfish.cn/search?keywords='+keyWord)
						.then(
							function(response){
								console.log(response);
								that.songs=response.data.result.songs;		
							},
							function(error){
								
							}
						)
					},
					searchSongId:function(id){
						var that=this;
						axios.get('https://autumnfish.cn/song/url?id='+id)
						.then(
							function(response){			
								that.songUrl=response.data.data[0].url;
								console.log(that.songUrl);
							},
							function(error){
								
							}
						)
					},
					searchMVId:function(mvId){
						var that=this;
						axios.get('https://autumnfish.cn/mv/url?id='+mvId)
						.then(
							function(response){	
								that.mvUrl=response.data.data.url;
								console.log(that.mvUrl);
								that.isShow=true;
							},
							function(error){
								
							}
						)
					}
				}
			});
		</script>
		
	</body>
</html>

效果

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值