better-scroll 上拉加载 下拉刷新的问题

当数据不足一个页面时 better-scroll 无法滚动,是因为只有content的高度大于wrapper高度时候,才可以滚动。
在这个时候可以打印 this.scroll 看看
当this.scroll.hasVerticalScroll 为fasle的时候就是content的高度小于wrapper高度

直接强制修改 this.scroll.hasVerticalScroll = true
这样就能刷新了。
<template>
<div class="main">
<div class="herder">
<div @click="modelisshow" ><i v-if="ishow" class="on">金额不限</i><i v-else>金额不限</i><img v-if="ishow" src="~assets/images/icon-v.png" /><img v-else src="~assets/images/icon-v-i.png" /></div>
<div @click="modemonshow"><i v-if="monshow" class="on">所有贷款类型</i><i v-else>所有贷款类型</i><img v-if="monshow" src="~assets/images/icon-v.png"><img v-else src="~assets/images/icon-v-i.png" /></div>
</div>
<transition>
<div class="min-show" v-if="ishow">
<ul>
<li v-for="(item, index) in list" :key="index" v-bind:class="{ active: index == sumIndex }" @click="sumclike(item,index)">{{item.name}}</li>
</ul>
<div class="bg-color" @click="modelisshow"></div>
</div>
<div class="min-show" v-if="monshow">
<ul>
<li v-for="(item, index) in mon" :key="index" v-bind:class="{ active: index == typeIndex }" @click="typeclike(item,index)">{{item.name}}</li>
</ul>
<div class="bg-color" @click="modemonshow"></div>
</div>
</transition>
<div class="wrapper" ref="wrapper">
<div class="content">
<div class="newxin" v-if="down">
<img src="~assets/images/loading.gif" />
</div>
<div v-for="(items, index) of main" :key="index">
<div class="home-box" v-for="(item, index) of items" :key="index" @click="ApplyBtn(item.id)">
<img :src="item.logo" alt="" />
<div class="home-list">
<div class="top-list">
<h5>{{item.title}}</h5>
<div class="num-tit"><i>{{item.hit}}</i>已放款</div>
</div>
<div class="top-line">
<span class="tit">额度范围(元)</span>
<span class="num">{{item.loan_limit}}</span>
</div>
<div class="center-line">
<span class="tit">贷款周期(天)</span>
<span class="num">{{item.loan_during}}</span>
</div>
<div class="right-line">
<span class="tit">参考利率</span>
<span class="num">{{item.loan_rate}}%</span>
</div>
</div>
</div>
</div>
<div class="newxin-bottom" v-if="up"></div>
</div>
</div>
<div v-show="showtit">
<p class="notit"><img src="~assets/images/61542708710.jpg" alt=""></p>
</div>
<div v-show="loading" class="loading">
<img src="~assets/images/loading.gif" alt="">
</div>
<div v-show="showloading" class="loading">
<img src="~assets/images/loading.gif" alt="">
</div>
<div class="seize"></div>
</div>
</template>
<script>
import axios from 'axios'
import BScroll from 'better-scroll'
import util from '../../../util/util'
let page = 1
export default {
name: 'BorrowMain',
data () {
return {
main: [],
list: [],
mon: [],
msg: '',
showtit: false,
ishow: false,
monshow: false,
loading: false,
sumIndex: 0,
typeIndex: 0,
sum: '',
dropDown: false,
type: '',
showloading: '',
loadingConnecting: false,
down: false,
up: true,
pulldownTip: {
text: '下拉刷新',
textup: '上拉加载更多',
rotate: ''
}
}
},
methods: {
minlist () {
axios.post(this.GLOBAL.ajaxurl + 'api/v1/product/getscreen', {
loanKey: this.route.params.loanKey }) .then(this.minlistSucc) }, minlistSucc (res) { res = res.data if (res.code === 200) { this.list = res.data.screen this.mon = res.data.position_type[1].value } }, modelisshow () { this.ishow = !this.ishow if (this.monshow === true) { this.monshow = false } }, modemonshow () { this.monshow = !this.monshow if (this.ishow === true) { this.ishow = false } }, sumclike (data, index) { this.sumIndex = index this.sum = data.screen_id this.ishow = !this.ishow axios.post(this.GLOBAL.ajaxurl + 'api/v1/product/getList', { loanKey: this.route.params.loanKey,
choose: this.sum,
position: this.type
})
.then(this.sumSucc)
},
sumSucc (res) {
res = res.data
if (res.code === 200) {
this.main = [res.data.data]
this.showtit = false
}
if (JSON.stringify(res.data) === '{}') {
this.showtit = true
}
},
typeclike (data, index) {
this.typeIndex = index
this.type = data.position
this.monshow = !this.monshow
axios.post(this.GLOBAL.ajaxurl + 'api/v1/product/getList', {
loanKey: this.route.params.loanKey, choose: this.sum, position: this.type }) .then(this.typeSucc) }, typeSucc (res) { res = res.data if (res.code === 200) { this.main = [res.data.data] this.showtit = false } if (JSON.stringify(res.data) === '{}') { this.showtit = true } }, ApplyBtn (id) { axios.post(this.GLOBAL.ajaxurl + 'api/v1/product/hit', { loanKey: this.route.params.loanKey,
product_id: id,
client: 'wechat',
openid: sessionStorage.getItem('openid')
})
.then(this.ApplyBtnSucc)
},
ApplyBtnSucc (res) {
res = res.data
if (res.code === 200) {
window.location.href = res.data
}
},
getMainInfo () {
this.showloading = true
axios.post(this.GLOBAL.ajaxurl + 'api/v1/product/getList', {
page: page++,
loanKey: this.route.params.loanKey, choose: this.sum, position: this.type }) .then(this.getMainInfoSucc) }, getMainInfoSucc (res) { this.showloading = false res = res.data if (res.code === 200) { this.main.push(res.data.data) } if (JSON.stringify(res.data) === '{}') { this.msg = res.msg this.openBottom() } if (JSON.stringify(res.data) !== '{}') { this.showtit = false } }, openBottom () { this.toast(this.msg)
},
BS () {
if (!this.refs.wrapper) { return } // better-scroll的初始化 this.scroll = new BScroll(this.refs.wrapper, {
probeType: this.probeType,
click: this.click,
scrollX: this.scrollX,
scrollY: this.scrollY
})
this.scroll.on('scroll', pos => {
this.scroll.hasVerticalScroll = true
if (pos.y > 50) {
this.down = true
} else {
this.down = false
}
})
this.scroll.on('touchEnd', pos => {
if (pos.y > 50) {
axios.post(this.GLOBAL.ajaxurl + 'api/v1/product/getList', {
page: '1',
loanKey: this.route.params.loanKey, choose: this.sum, position: this.type }).then(function (res) { res = res.data if (res.code === 200) { this.toast('刷新成功!')
this.main = [res.data.data]
}
}.bind(this))
this.down = false
}
if (this.scroll.maxScrollY > pos.y + 10) {
this.getMainInfo()
this.scroll.finishPullUp()
this.scroll.refresh()
this.toast('加载成功!') } }) } }, mounted () { setTimeout(() => { this.BS() }, 20) this.minlist() this.getMainInfo() util.getwechat(this.route.params.loanKey)
},
watch: {
data () {
setTimeout(() => {
this.BS()
}, this.refreshDelay)
}
},
props: {
/**
* 1 滚动的时候会派发scroll事件,会截流。
* 2 滚动的时候实时派发scroll事件,不会截流。
* 3 除了实时派发scroll事件,在swipe的情况下仍然能实时派发scroll事件
/
probeType: {
type: Number,
default: 3
},
/
*
* 点击列表是否派发click事件
/
click: {
type: Boolean,
default: true
},
/
*
* 是否开启横向滚动
/
scrollX: {
type: Boolean,
default: false
},
scrollY: {
type: Boolean,
default: true
},
/
*
* 是否派发滚动事件
/
listenScroll: {
type: Boolean,
default: true
},
/
*
* 列表的数据
/
data: {
type: Array,
default: null
},
/
*
* 是否派发滚动到底部的事件,用于上拉加载
/
pullup: {
type: Boolean,
default: false
},
/
*
* 是否派发顶部下拉的事件,用于下拉刷新
/
pulldown: {
type: Boolean,
default: true
},
/
*
* 是否派发列表滚动开始的事件
/
beforeScroll: {
type: Boolean,
default: true
},
/
*
* 当数据更新后,刷新scroll的延时。
*/
refreshDelay: {
type: Number,
default: 30
}
},
beforeDestroy () {
page = 1
}
}
</script>

<style lang="stylus" scoped>
@import '~assets/styles/varibles.styl'
.main
padding-top 1.6rem
.herder
width 100%
height .9rem
background #FFFFFF
position fixed
top 0
left 0
z-index 100
div
width 50%
height .9rem
line-height .9rem
float left
text-align center
color #666666
font-size .26rem
.on
color color img width .21rem height .15rem margin-left .2rem .min-show width 100% height 100% position fixed top 0 left 0 background:rgba(0,0,0,0.2); z-index 99 .bg-color width 100% height 100% position absolute z-index 100 left 0 ul padding .25rem 5% position fixed width 90% z-index 101 top .9rem background #FFFFFF li width 30% height .6rem background #CCCCCC color #ffffff line-height .6rem text-align center float left margin-left 3% font-size .26rem margin-bottom .3rem border-radius .1rem .active backgroundbackground
.wrapper
width 100%
height 85%
position absolute
overflow hidden
top 8%
bottom 8%
.newxin
width 100%
height .5rem
img
width .4rem
height .4rem
display block
margin 0 auto
.home-box
margin 0 .25rem;
height 100%
background #ffffff url("~assets/images/flow-right.png") no-repeat 96% center
background-size .17rem .34rem
padding .3rem .4rem .3rem .2rem
overflow hidden
box-shadow:0 0.04rem 0.2rem 0 rgba(198,198,198,0.18);
border-radius 0.18rem
margin-bottom 0.3rem
img
width 1.4rem
height 1.4rem
float left
display block
margin-right .1rem
.home-list
width 4.6rem;
float left
.top-list
width 100%;
height .42rem;
margin-bottom .2rem;
h5
width 2.1rem
color #333333
font-size .32rem
height .42rem
line-height .42rem
font-weight bold
text-align left
float left
white-space nowrap
text-overflow ellipsis
overflow hidden
.num-tit
height .42rem;
line-height .42rem
font-size .24rem
color #999999
float right
text-align right
i
color color .top-line width 100% height .36rem margin-bottom .1rem .tit font-size .24rem color #999999 line-height .36rem width 2rem float left .num colorcolor
float left
font-size .26rem
width 2.5rem
white-space nowrap
text-overflow ellipsis
overflow hidden
line-height .36rem
.center-line
width 55%
height .36rem
float left
overflow hidden
.tit
font-size .24rem
color #999999
line-height .36rem
.num
color #333333
font-size .28rem
line-height .36rem
.right-line
width 45%
height .34rem
display block
float right
text-align right
.tit
font-size .24rem
color #999999
line-height .34rem
.num
color #333333
font-size .26rem
line-height .34rem
.newxin
width 100%
height .5rem
text-align center
line-height .5rem
.newxin-bottom
width 100%
height .5rem
position absolute
bottom -1rem
text-align center
.seize
width 100%
height 1.25rem
.notit
text-align center
font-size .36rem
margin-top 1rem
img
width 4rem
.loading
position fixed
top 0
right 0
bottom 0
left 0
z-index 998
img
position absolute
left 50%
top 50%
width .8rem
height .8rem
transform translate(-50%, -50%)
.loading
position fixed
top 0
right 0
bottom 0
left 0
z-index 998
img
width .8rem
height .8rem
position absolute
left 50%
top 50%
transform translate(-50%, -50%)
.v-enter, .v-leave-to
opacity 0
.v-enter-active, .v-leave-active
transition opacity .2s
</style>

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,519评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,842评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,544评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,742评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,646评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,027评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,513评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,169评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,324评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,268评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,299评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,996评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,591评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,667评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,911评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,288评论 2 345
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,871评论 2 341

推荐阅读更多精彩内容

  • 谢谢作者的文章 非常喜欢 请允许收藏! 博客园首页博问闪存新随笔订阅管理 vue之better-scroll的封装...
    peng凯阅读 16,498评论 2 5
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,689评论 0 3
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,438评论 0 13
  • 我爱的男子 在我的诗歌里临水而居 吟唱古拙的诗经 负手而立 我爱的男子 在我的诗歌里策马疾行 奔向秦汉的明月 弯弓...
    暗香盈梦阅读 101评论 2 2
  • 我确定,对你们不仅仅只是喜欢……晚安,雨有点大,肚子有点饿,看到宝宝们在吃串串,我还是自律点,毕竟明早还跟陈老师约...
    LoveYoga喵喵阅读 121评论 0 0