用vue制作的一个简易的音乐播放器,无样式

 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="player">
      <div id="search_bar">
        <input
          type="text"
          autocomplete="off"
          v-model="query"
          @keyup.enter="searchMusic"
        />
      </div>
      <div>
        <ul>
          <li v-for="item in music">
            <a href="javascript:;" @click="playMusic(item.id)">播放</a>
            {{item.name}}
            <span v-if="item.mvid>0" @click="playMv(item.mvid)"><i>mv</i></span>
          </li>
        </ul>
      </div>
      <div>
        <img :src="imgSrc" alt="" />
      </div>
      <div>
        <audio
          :src="musicUrl"
          ref="audio"
          controls
          autoplay
          loop
          @play="play"
          @pause="pause"
        ></audio>
      </div>
      <div v-show="isShow" style="display: none;">
        <video :src="mvUrl" controls></video>
      </div>
      <div :class="{playing:isPlaying}">
        <img src="" alt="" />
      </div>
      <div>
        <dl v-for="item in hotComments">
          <dt>
            <img :src="item.user.avatarUrl" alt="头像" />
          </dt>
          <dd>{{item.nickname}}</dd>
          <dd>{{item.content}}</dd>
        </dl>
      </div>
    </div>
    <script src="https://cdn.bootcss.com/axios/0.19.2/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="综合应用.js"></script>
  </body>
</html>
var vm = new Vue({
  el: "#player",
  data: {
    query: "",
    music: [],
    musicUrl: "",
    imgSrc: "",
    hotComments: [],
    isPlaying: false,
    isShow: false,
    mvUrl: "",
  },
  methods: {
    searchMusic: function () {
      var that = this;
      axios
        .get("https://autumnfish.cn/search?keywords=" + this.query)
        .then(function (response) {
          // console.log(response);
          that.music = response.data.result.songs;
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    playMusic: function (musicId) {
      // console.log(musicId);
      var that = this;
      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) {
          alert(err);
        };
      axios
        .get("https://autumnfish.cn/song/detail?ids=" + musicId)
        .then(function (response) {
          //   console.log(response)
          // console.log(response.data.songs[0].al.picUrl);
          that.imgSrc = response.data.songs[0].al.picUrl;
        })
        .catch(function (error) {
          alert(error);
        });
      axios
        .get("https://autumnfish.cn/comment/hot?type=0&id=" + musicId)
        .then(function (response) {
          console.log(response.data.hotComments);
          that.hotComments = response.data.hotComments;
        })
        .catch(function (error) {
          console.log(error)
        });
    },
    play: function () {
      // console.log("play");
      this.isPlaying = true;
    },
    pause: function () {
      // console.log("pause");
      this.isPlaying = false;
    },
    playMv: function (mvid) {
      var that = this;
      axios.get("https://autumnfish.cn/mv/url?id=" + mvid)
        .then(function (response) {
          // console.log(response.data.data.url)
          that.isShow = true;
          that.mvUrl = response.data.data.url;
        })
        .catch(function (error) {
        })
    }
  },
});

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值