项目是基于Vue,成品是一个移动端的单页面应用音乐播放器,来源于imooc的实战课程,自己通过看视频来完成这个应用。
项目的大致流程是Vue-cli构建开发环境,分析需求,设计构思,规划目录结构,开始编码。
所有数据都来自于QQ音乐,抓取自QQ的接口,大部分接口都是JSONP,抓取比较容易,其中一些接口限制了host,不能直接抓取,采用的方法是用axios代理,设置header,以此绕过host的限制。
Vue+Vuex+Vue-Router+Vue-cli+Stylus+Axios+Better-scroll
播放器组件可谓是整个项目的核心,当然数据处理和用户体验方面也是不简单的(播放器是全局组件,放在App.vue下面,通过Vuex传递数据,触发action提交mutation,从而使播放器开始工作。
通过调用QQ音乐的JSONP接口,获取的数据并不能直接拿来用,需要做进一步的规格化。
在请求JSONP的时候,用到了一个JSONP库。使用时,就是将请求的参数拼接在请求url上,然后调用这个库的jsonp方法。
将请求的数据格式化后再通过Vuex传递,组件间共享,实现歌曲的播放切换等。
该项目的很多地方都涉及到滚动,包括下拉滚动,下拉滚动刷新等,这里面用到了一个js库better-scroll,来实现所有涉及到的滚动。
其他动画包括了Vue的transition动画,路由之间切换时的简单动画,播放器打开时的动画。
打开页面时的加载Loading效果,其实就是一个Loading组件。
为了减少流量,图片加载使用了懒加载的方式。
自己通过这个项目学到很多关于vue单页面开发的知识,还需要更加融合贯通,毕竟是自己的第一个vue作品,完成度也不是很高,但是希望在日后的学习中能够有所提高。