练习的demo来自于黑马程序员Vue教程,只关注于html和js的部分,css样式基于已有模板未作修改。

简单的计数增减。
button按钮绑定点击事件,数值达到上下限时弹出提示。


图片上下张的切换功能。

var app = new Vue({
    el: '#app',
    data: {
        city:'',
        weatherList:[]
    },
    methods: {
        searchWeather: function(){
            // console.log('stesttesttest');
            // console.log(this.city);
            // 调用接口
            // 保存this
            var that = this;
            axios.get("http://wthrcdn.etouch.cn/weather_mini?city="+this.city)
            .then(function(response){
                //console.log(response)
                //console.log(response.data.data.forecast);
                that.weatherList = response.data.data.forecast
            })
            .catch(function(err){})
        },
        changeCity:function(city){
            this.city = city;
            this.searchWeather();
        }
    }
})

var app = new Vue({
    el: '#player',
    data: {
        // 查询关键字
        query: "",
        // 歌曲数组
        musicList: [],
        // 歌曲地址
        musicUrl: "",
        // 歌曲封面
        musicCover: "",
        // 歌曲评论
        hotComments: [],
        // 动画播放状态
        isPlaying: false,
        // 遮罩层的显示状态
        isShow: false,
        // mv地址
        mvUrl: ""
    },
    methods: {
        searchMusic:function(){
            var that = this;
            if(that.query == 0){
              return
            }
            axios.get('https://autumnfish.cn/search?keywords='+this.query)
            .then(function(response){
                //console.log(response);
                that.musicList = response.data.result.songs;
                console.log(response.data.result.songs);
            },
            function(err){})
            //清空搜索
            this.query = ''
        },
        //播放歌曲
        playMusic: function(musicId){
          //console.log(musicId);
          var that = this;
          axios.get("https://autumnfish.cn/song/url?id="+musicId)
          .then(function(response){
            //console.log(response);
            //console.log(response.data.data[0].url);
            that.musicUrl = response.data.data[0].url;
          },
          function(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.musicCover = response.data.songs[0].al.picUrl;
          },function(err){})
          //歌曲评论
          axios.get("https://autumnfish.cn/comment/hot?type=0&id="+musicId)
          .then(function(response){
            //console.log(response);
            console.log(response.data.hotComments);
            that.hotComments = response.data.hotComments;
          },function(err){})
        },
        //歌曲播放
        play:function(){
          this.isPlaying = true;
          //清空mv
          this.mvUrl =''
        },
        //歌曲暂停
        pause:function(){
          this.isPlaying = false;
        },
        //播放mv
        playMV:function(mvid){
          var that = this;
          axios.get("https://autumnfish.cn/mv/url?id="+mvid).then(
            function(response){
              //console.log(response);
              //console.log(response.data.data.url);
              that.isShow = true;
              //暂停歌曲播放
              that.$refs.audio.pause()
              that.mvUrl = response.data.data.url;
            },
            function(err){}
          )
        },
        //关闭mv
        closeMV:function(){
          this.isShow = false;
          //暂停mv播放
          this.$refs.video.pause()
        },
        //搜索历史记录中的歌曲
        historySearch(history){
          this.query = history;
          this.searchMusic();
          this.showHistory = false;
        }
    }
})
后面计划再针对音乐播放器进行功能完善,然后学习css样式。