Vue 2.0 高级实战-开发移动端音乐WebApp 课程笔记(第九章 排行榜及详情页开发)
排行页面布局介绍及排行榜数据抓取
添加api/rank.js1
2
3
4
5
6
7
8
9
10
11
12
13import jsonp from 'common/js/jsonp'
import {commonParams, options} from './config'
export function getTopList() {
const url = 'https://c.y.qq.com/v8/fcg-bin/fcg_myqq_toplist.fcg'
const data = Object.assign({}, commonParams, {
needNewCode: 1,
platform: 'h5'
})
return jsonp(url, data, options)
}
排行页排行榜数据应用
新建组件rank
榜单详情页布局介绍及Vuex实现路由数据通讯
新建组件top-list
榜单详情页数据抓取和应用
1 | export function getMusicList(topid) { |
带排行的song-list组件扩展和应用
添加dom
1
2
3<div class="rank" v-show="rank">
<span :class="getRankCls(index)">{{getRankText(index)}}</span>
</div>添加props
1
2
3
4rank: {
type: Boolean,
default: false
}添加methods
1
2
3
4
5
6
7
8
9
10
11
12getRankCls(index) {
if (index <= 2) {
return `icon icon${index}`
} else {
return 'text'
}
},
getRankText(index) {
if (index > 2) {
return index + 1
}
}music-list添加props
1
2
3
4rank: {
type: Boolean,
default: false
}