rank.js封装接口
import 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, {
uin: 0,
notice: 0,
platform: 'h5',
needNewCode: 1
})
return jsonp(url, data, options)
}
数据获取
export default {
created () {
this._getTopList()
},
methods: {
_getTopList () {
getTopList().then((res) => {
if (res.code === ERR_OK) {
console.log(res)
}
})
}
}
}
使用如下:
定义一个data:
data () {
return {
topList: []
}
},
<div class="rank" ref="rank">
<scroll :data="topList" class="toplist" ref="toplist">
<ul>
<li class="item" v-for="item in topList" :key="item.id">
<div class="icon">
<img width="100" height="100" :src="item.picUrl">
</div>
<ul class="songlist">
<li class="song" v-for="(song, index) in item.songList" :key="index">
<span>{{index + 1}}</span>
<span>{{song.songname}}-{{song.singername}}</span>
</li>
</ul>
</li>
</ul>
<div class="loading-container" v-if="!topList">
<loading></loading>
</div>
</scroll>
</div>
布局如下:
.rank
position fixed
top 88px
left 0
right 0
bottom 0
.toplist
height: 100%
overflow: hidden
.item
display flex
margin 0 20px
padding-top 20px
&.last-child
padding-bottom 20px
.icon
flex 0 0 100px
width 100px
height 100px
.songlist
flex 1
display flex
flex-direction column
justify-content center
padding 0 20px
height 100px
overflow hidden
background: $color-highlight-background
color: $color-text-d
font-size: $font-size-small
.song
no-wrap()
line-height: 26px
.loading-container
position: absolute
width: 100%
top: 50%
transform: translateY(-50%)