• vue.js音乐播放器


    //  music.html

    <!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>Document</title>
        <script src="../vue.js"></script>
        <!--<script src="https://unpkg.com/axios/dist/axios.min.js"></script>-->
        <script src="../js/axios.min.js"></script>
    </head>
    <body>
        <div class="wrap">
            <!--搜索区域-->
            <div class="search_bar" id="player">
                <!--搜索歌曲-->
                <input type="text" autocomplete="off" v-model="query" @keyup.enter="searhMusic">
                <div>
                    <ul>
                        <div style="float: left;margin:20px;">
                            <li v-for="(item,idex) in music">
                                <span>{{idex+1}}</span>
                                {{item.name}}
                                <a href="javascript:;" @click="playMusic(item.id,item.name)">播放</a>
                            </li>
                        </div>
                       
                        <div style="float: left;margin:20px;">
                            <img v-bind:src="musicCover" width="260px" height="260px" v-show="flag">
                            <span><p>播放:{{musicName}}</p></span>
                            <audio ref="audio" v-bind:src="musicUrl" controls autoplay loop class="myaudio"> </audio>
                           
                        </div>
                    </ul>
                </div>
               

            </div>

        </div>
        <script src="./main.js"></script>
        
    </body>
    </html>

      // js 文件

    /*
    歌曲搜索接口
    请求地址:https://autumnfish.cn/search
    请求方式:get
    请求关键字:keywords
    相应内容

    获取歌曲地址
    https://autumnfish.cn/song/url

    //获取歌曲详情
    https://autumnfish.cn/song/detail

    */
    var vu=new Vue({
        el:"#player",
        data:{
            query:"",
            music:[],
            musicUrl:"",
            musicName:"",
            musicCover:"",
            flag:false
           
        },
        methods:{
            searhMusic:function(){
                var that=this;
                axios.get("https://autumnfish.cn/search?keywords="+this.query).then(function(res){
                    console.log(res);
                    if(res.data.result !=null){
                        that.music=res.data.result.songs
                    }
                    console.log(that.music)
                },
                function(err){

                }
                )
            },
            //歌曲播放
            playMusic:function(id,name){
                this.musicName=name;
                var that=this;
                this.flag=true;
                axios.get("https://autumnfish.cn/song/url?id="+id).then(function(res){
                    console.log("音乐播放路径")
                    console.log(res)
                    that.musicUrl=res.data.data[0].url;
                },
                function(err){

                }
                )
                //歌曲详情获取
                axios.get("https://autumnfish.cn/song/detail?ids="+id).then(function(res){
                    console.log("获取歌曲详情");
                    console.log(res);
                    console.log(res.data.songs[0].al.picUrl);
                    that.musicCover=res.data.songs[0].al.picUrl;

                },function(err){

                })
            }
           
        }
    })

      

  • 相关阅读:
    ecshop后台新建一个模块,添加分页
    Mysql中设置远程访问的方法
    Thinkphp 3.2中文章详情页的上一篇 下一篇文章功能
    Thinkphp 3.2.2 利用phpexcel完成excel导出功能
    Thinkphp 3.2中字符串截取
    服务管理-文件服务器
    nginx-伤心的事
    shell-awk
    shell-sed
    shell-函数、数组、正则
  • 原文地址:https://www.cnblogs.com/xianz666/p/14845478.html
Copyright © 2020-2023  润新知