singer页面加载listview无法滚动
来源:5-4 listview 基础组件的开发和应用-滚动列表实现
浅笑醉红尘
2017-11-03
<template> <scroll class="listview" :data="data" ref="listview"> <ul> <li v-for="group in data" class="list-group" ref="listGroup"> <h2 class="list-group-title">{{group.title}}</h2> <uL> <li v-for="item in group.items" class="list-group-item"> <img class="avatar" v-lazy="item.avatar"> <span class="name">{{item.name}}</span> </li> </uL> </li> </ul> <div class="list-shortcut" @touchstart.stop.prevent="onShortcutTouchStart"> <ul> <li v-for="(item, index) in shortcutList" :data-index="index" class="item">{{item}}</li> </ul> </div> </scroll> </template> <script type="text/ecmascript-6"> import Scroll from 'base/scroll/scroll' import {getData} from 'common/js/dom' export default { props: { data: { type: Array, default: [] } }, computed: { shortcutList () { return this.data.map((group) => { return group.title.substr(0, 1) }) } }, mounted () { setTimeout(() => { this.$refs.scroll.refresh() }, 20) }, methods: { onShortcutTouchStart (e) { let anchorIndex = getData(e.target, 'index') console.log(anchorIndex) this.$refs.listview.scrollToElement(this.$refs.listGroup[anchorIndex], 0) } }, components: { Scroll } } </script> <style scoped lang="stylus" rel="stylesheet/stylus"> @import "~common/stylus/variable" .listview position: relative width: 100% height: 100% overflow: hidden background: $color-background .list-group padding-bottom: 30px .list-group-title height: 30px line-height: 30px padding-left: 20px font-size: $font-size-small color: $color-text-l background: $color-highlight-background .list-group-item display: flex align-items: center padding: 20px 0 0 30px .avatar width: 50px height: 50px border-radius: 50% .name margin-left: 20px color: $color-text-l font-size: $font-size-medium .list-shortcut position: absolute z-index: 30 right: 0 top: 50% transform: translateY(-50%) width: 20px padding: 20px 0 border-radius: 10px text-align: center background: $color-background-d font-family: Helvetica .item padding: 3px line-height: 1 color: $color-text-l font-size: $font-size-small &.current color: $color-theme .list-fixed position: absolute top: 0 left: 0 width: 100% .fixed-title height: 30px line-height: 30px padding-left: 20px font-size: $font-size-small color: $color-text-l background: $color-highlight-background .loading-container position: absolute width: 100% top: 50% transform: translateY(-50%) </style>
(上面是)listview代码实现
<template> <div class="singer"> <list-view :data="singers"></list-view> </div> </template> <script type="text/ecmascript-6"> import {getSingerList} from 'api/singer' import {ERR_OK} from 'api/config' import Singer from 'common/js/singer' import ListView from 'base/listview/listview' const HOT_SINGER_LEN = 10 const HOT_NAME = '热门' export default { data () { return { singers: [] } }, created () { this._getSingerList() }, methods: { _getSingerList () { getSingerList().then((res) => { if (res.code === ERR_OK) { this.singers = this._normalizeSinger(res.data.list) } }) }, _normalizeSinger (list) { let map = { hot: { title: HOT_NAME, items: [] } } for (let [index, item] of list.entries()) { if (index < HOT_SINGER_LEN) { map.hot.items.push(new Singer({ name: item.Fsinger_name, id: item.Fsinger_mid })) } const key = item.Findex if (!map[key]) { map[key] = { title: key, items: [] } } map[key].items.push(new Singer({ name: item.Fsinger_name, id: item.Fsinger_mid })) } // 为了得到有序列表,我们需要处理 map let ret = [] let hot = [] for (let key in map) { let val = map[key] if (val.title.match(/[a-zA-Z]/)) { ret.push(val) } else if (val.title === HOT_NAME) { hot.push(val) } } ret.sort((a, b) => { return a.title.charCodeAt(0) - b.title.charCodeAt(0) }) return hot.concat(ret) } }, components: { ListView } } </script> <style scoped lang="stylus" rel="stylesheet/stylus"> </style>
(上面是)singer引用
数据可以加载出来但在手机无法滚动,但可以用滚轮滚动
写回答
1回答
-
http://ustbhuangyi.com/music/#/singer 这个页面是否有问题,若没问题,建议你去对比一下我的最新代码。另外手机端要用真机做测试。
022017-11-12
相似问题