一、input输入框 绑定enter键获取keyword值
<div class="search"><el-input v-model="keyword" @keyup.enter.native="handleUp"> </el-input></div><div class="name">{{keyword}}</div> // 搜索什么就显示什么
http请求
import axios from 'axios'export default {...data(){return{keyword:"成都",id:"",url:"",}},methods:{async handleUp(){var url =`http://192.168.14.49:5000/search?keywords=${this.keyword}`;await axios.get(url).then(res=>{this.id=res.data.result.songs[0].id; // 获取id})var songUrl = `https://music.aityp.com/song/url?id=${this.id}`;await axios.get(songUrl).then(res=>{this.url = res.data.data[0].url; // 二次请求http 拿取url})}
二、渲染数据
<audio controls autoplay :src="url"></audio>
三、音乐播放,图片旋转
给音乐绑定两个事件
<audio controls autoplay :src="url"@play="onPlay"@pause="onPause" ref="audio"></audio>
onPlay(){this.isPlay=true},onPause(){this.isPlay = false},
给图片一个点击事件,可以通过控制图片的旋转,暂停来控制音乐的播放和暂停
<img class="pic" @click="handle" src="./assets/20180901160236_mybsx.jpg" alt="">
handle(){if(this.isPlay){this.$refs.audio.pause()this.isPlay = false}else{this.$refs.audio.play()this.isPlay = true}}
图片旋转的css样式 ,用三目选算符取控制
<img class="pic" :class="isPlay?'rot':'end'"@click="handle" src="./assets/20180901160236_mybsx.jpg" alt="">
@keyframes rotated {0%{transform: rotate(0deg)}100%{transform:rotate(360deg)}}.rot{animation: rotated 15s linear infinite;animation-play-state: running;}.end{animation: rotated 15s linear infinite;animation-play-state: paused;}
