使用vux实现上拉刷新的总结
最近公司在研发app,选择了基于Vue框架的vux组件库,现总结在实现上拉刷新功能遇到的坑:
1.问题:只刷新一次,解决方法:需要自己手动重置状态
this.scrollerStatus.pullupStatus = ‘default’,
2.问题:不能滚动,解决方法:因为启用keep-alive缓存,需要设置
activated () {
this.$refs.scroller.reset()
}
如果还没效果,请在获取后台数据后,执行如下代码
this.$nxtTick(() => {
this.$refs.scroller.reset()
})
贴出整个页面的代码。
<template>
<div style="height:100%;"> <x-header slot="header" :left-options="{showBack: false}" >会议列表
<a slot="right" v-on:click="show = true" > <icon type="search"></icon> </button> </a>
</x-header> <!-- 会议列表 -->
<scroller v-model="scrollerStatus" height="-46" lock-x scrollbar-y ref="scroller" :bounce="isbounce" :use-pullup="showUp" :pullup-config="upobj" @on-pullup-loading="selPullUp" >
<div class="box2">
<p v-for="list, index in lists">
<router-link :to="{ path: list.id } ">
<p style="height:40px;">
<span class="spanMeetTitle" v-html='(index+1) + " . " + list.name' ></span>
<span class="spanMeetStatu" v-html='list.status'></span>
</p>
<p class="prevSuper">
<form-preview header-label="" header-value="" :bodyItems="list" :footer-buttons="buttons1"></form-preview>
</p>
</router-link>
<hr>
</p>
</div>
</scroller> <!-- 导航 -->
<Home></Home> <!-- 搜索 -->
<popup v-model="show" @on-hide="log('hide')" @on-show="log('show')" height="93%">
<div class="popup0">
<group>
<x-input v-model='meetName' placeholder="请输入“会议名称”搜索"></x-input>
<div style="float:left;margin-top: -36px;"><icon type="search"></icon></div>
</group>
<!--
<group>
<checklist :max=1 title="会议审批状态" required :options="commonList" v-model="checkStatus" @on-change="change"></checklist>
</group> --> <group title="会议审批状态">
<radio :options="commonList" v-model="checkStatus" @on-change="change"></radio>
</group> <group title="会议类型">
<selector placeholder="请选择会议类型" v-model="checkType" :options="meetType"></selector>
</group> <group title="召开时间">
<flexbox>
<flexbox-item>
<div class="flex-demo" style="background-color:white;color:black;height:45px">
<datetime title='' placeholder="请选择" v-model="startTime" format="YYYY-MM-DD HH:mm" @on-change="change" ></datetime>
</div>
</flexbox-item>
至
<flexbox-item>
<div class="flex-demo" style="background-color:white;color:black;height:45px">
<datetime title='' placeholder="请选择" v-model="stopTime" format="YYYY-MM-DD HH:mm" @on-change="change" ></datetime>
</div>
</flexbox-item>
</flexbox>
</group>
<br>
<flexbox orient="vertical">
<flexbox-item><div class="flex-demo" v-on:click="toSearch" >确定</div></flexbox-item>
<flexbox-item><div class="flex-demo" v-on:click="show = false" style="background-color:white;color:black">取消</div></flexbox-item>
</flexbox> </div>
</popup> <toast v-model="showToast">已加载全部数据</toast> <loading v-model="isShowLoading" :text="textLoading"></loading> <alert v-model="isShowAlert" :title="AlertCongratulations" > {{ alertMessage }}</alert>
</div>
</template> <style type="text/css">
.weui-form-preview__value{
font-size: 1.1em !important;
color: black;
}
.spanMeetTitle{
float: left;
border-radius: 13px;
padding:10px 6px;
font-size: 15px;
font-weight: bold;
margin-left: 3px;
color: black;
}
.spanMeetStatu{
float: right;
background-color: green;
border-radius: 10px;
padding:6px 5px;
color: white;
font-size: 13px;
margin-top: 5px;
}
.flex-demo{
height: 30px;padding-top: 5px;
}
.selected{
color: blue !important;
background-color: transparent;
}
.popup0 {
padding-bottom:15px;
height:200px;
}
.popup1 {
width:100%;
height:100%;
}
.popup2 {
padding-bottom:15px;
height:400px;
}
.box1 {
height: 100px;
position: relative;
width: 1490px;
}
.box1-item {
width: 200px;
height: 100px;
background-color: #ccc;
display:inline-block;
margin-left: 15px;
float: left;
text-align: center;
line-height: 100px;
}
.box1-item:first-child {
margin-left: 0;
}
.box2-wrap {
height: 300px;
overflow: hidden;
}
</style> <script>
import { XHeader, Group, FormPreview, Tabbar, TabbarItem, Scroller, Icon, Popup, XSwitch, Toast, XInput, Checklist, Datetime, Flexbox, FlexboxItem, Selector, Loading, Alert, Radio } from 'vux'
import Home from './Home' export default {
components: {
XHeader,
Home,
Group,
FormPreview,
Tabbar,
TabbarItem,
Scroller,
Icon,
Popup,
XSwitch,
Toast,
XInput,
Checklist,
Datetime,
Flexbox,
FlexboxItem,
Selector,
Loading,
Alert,
Radio
},
data () {
return {
type: '1',
PageIndex: 0,
show: false,
showToast: false,
showloading: false,
showUp: true,
isbounce: false,
isShowAlert: false,
AlertCongratulations: '条件有误',
textloading: '加载中',
alertMessage: '‘召开时间’ 不能大于 ‘结束时间’',
value: '',
meetName: '',
startTime: '',
stopTime: '',
meetType: [],
commonList: [{key: '20', value: '审批中'}, {key: '50', value: '审批通过'}, {key: '', value: '全部'}],
checkStatus: '',
checkType: '',
commonList2: [],
results: [],
lists: [[]],
buttons1: [{
style: 'primary',
text: '查看更多',
link: '/Message'
}],
upobj: {
content: '请上拉刷新数据',
pullUpHeight: 60,
height: 40,
autoRefresh: false,
downContent: '请上拉刷新数据',
upContent: '请上拉刷新数据',
loadingContent: '加载中...',
clsPrefix: 'xs-plugin-pullup-'
},
isShowLoading: false,
textLoading: '加载中',
scrollerStatus: {
pullupStatus: 'default'
}
}
},
mounted () {
console.log(this.scrollerStatus.pullupStatus)
this.getMeetList(true)
this.getMeetType()
this.$nextTick(() => {
this.$refs.scroller.reset()
})
},
methods: {
log (str) {
console.log(str)
},
getMeetList (isEmpty) {
var APPROVE_STATUS = this.checkStatus
var MEETING_TYPE = this.checkType
this.isShowLoading = true
this.$http.post(global.httpsUrl + '/Meet/GetMeetList', {'HumanId': global.userid, 'KEY': this.meetName, 'APPROVE_STATUS': APPROVE_STATUS, 'MEETING_TYPE': MEETING_TYPE, 'START_DATE': this.startTime, 'STOP_DATE': this.stopTime, 'PageIndex': this.PageIndex, 'PageSize': '2'}).then(response => {
// sucess callback
console.log('111')
var data = response.body.Data
if (isEmpty) {
this.lists = []
this.show = false
} else {
if (data && data.length === 0) {
this.showToast = true
this.isShowLoading = false
this.scrollerStatus.pullupStatus = 'disabled' // 禁用下拉
return
}
}
for (var i = 0; i < data.length; i++) {
if (data[i].APPROVE_STATUS < 20) {
break
}
var personName = data[i].PERSION1_NAME
if (personName && personName.length > 0) {
personName = personName.substring(0, personName.indexOf('>'))
}
var meetlist = []
var obj = {
label: '地点',
value: data[i].ADDRESS
}
meetlist.push(obj)
obj = {
label: '主持人',
value: personName
}
meetlist.push(obj)
obj = {
label: '召开时间',
value: global.formatDate.methods.toSet(data[i].ACT_START_TIME, 'yyyy-MM-dd HH:mm')
}
meetlist.push(obj)
obj = {
label: '会议类型',
value: data[i].MEETING_TYPE_NAME
}
meetlist.push(obj)
meetlist.id = 'FromMeet/' + data[i].MEETING_MINUTES_GUID + '/123'
meetlist.name = data[i].MEETING_NAME
var vstatus = '审批中'
if (data[i].APPROVE_STATUS === 50) {
vstatus = '审批通过'
}
meetlist.status = vstatus
this.lists.push(meetlist)
}
this.isShowLoading = false
if (!isEmpty) {
this.scrollerStatus.pullupStatus = 'default'
// this.$refs.scroller.reset()
console.log(this.scrollerStatus.pullupStatus)
this.$nextTick(() => {
this.$refs.scroller.reset()
})
}
}, response => {
// error callback
this.show = false
})
},
showSearch () {
this.show = true
},
change (val) {
console.log('change', val)
console.log(this.startTime)
},
change2 (val) {
console.log('change', val)
},
resultClick () {
},
getResult () {
},
toSearch () {
console.log(2222)
if (this.startTime && this.stopTime && this.startTime > this.stopTime) {
this.isShowAlert = true
} else {
this.PageIndex = 0
this.getMeetList(true)
}
},
selPullUp () {
console.log('上拉刷新数据')
this.PageIndex++
this.getMeetList(false)
},
getMeetType () {
this.$http.post(global.httpsUrl + '/Meet/GetMeetType').then(response => {
// sucess callback
var data = response.body.Data
for (var i = data.length - 1; i >= 0; i--) {
var obj = {
key: data[i].TYPE_GUID,
value: data[i].TYPE_NAME
}
this.meetType.push(obj)
}
}, response => {
// error callback
})
}
},
activated () {
this.$refs.scroller.reset()
}
}
</script> <style lang="less">
@import '~vux/src/styles/1px.less'; .flex-demo {
text-align: center;
color: #fff;
background-color: #20b907;
border-radius: 4px;
background-clip: padding-box;
}
</style>
使用vux实现上拉刷新的总结的更多相关文章
- vux (scroller)上拉刷新、下拉加载更多
1)比较关键的地方是要在 scroller 组件上里加一个 ref 属性 <scroller :lockX=true height="-170" :pulldown-conf ...
- 【转】vux (scroller)上拉刷新、下拉加载更多
1)比较关键的地方是要在 scroller 组件上里加一个 ref 属性 <scroller :lockX="true" height="-170" :p ...
- SwipeRefreshLayout + RecyclerView 实现 上拉刷新 和 下拉刷新
下拉刷新和上拉刷新都用SwipeRefreshLayout 自带的进度条 布局 <?xml version="1.0" encoding="utf-8"? ...
- 使用MJRefresh遇到的一个问题,上拉刷新后tableview瞬间滑到最底部
最近用MJRefresh上拉刷新时遇到一个问题,就是上拉刷新后,tableview会瞬间滑到最底部,用户还要往回翻才能看到新刷出来的数据,体验十分不好.查了很久没找到原因,最后发现在refreshvi ...
- MUI - 上拉刷新/下拉加载
新闻信息列表必备的功能,支持Table,Ul等列表. 以下是DIV版本,在安卓端或者ios端必须使用双webview模式,传送门:http://dev.dcloud.net.cn/mui/pulldo ...
- Android UI之下拉刷新上拉刷新实现
在实际开发中我们经常要用到上拉刷新和下拉刷新,因此今天我写了一个上拉和下拉刷新的demo,有一个自定义的下拉刷新控件 只需要在布局文件中直接引用就可以使用,非常方便,非常使用,以下是源代码: 自定义的 ...
- Android PullToRefreshListView上拉刷新和下拉刷新
PullToRefreshListView实现上拉和下拉刷新有两个步骤: 1.设置刷新方式 pullToRefreshView.setMode(PullToRefreshBase.Mode.BOTH) ...
- ListView(2)最简单的上拉刷新,下拉刷新
最简单的上拉刷新和下拉刷新,当listview滚动到底部时向上拉刷新数据.当listview滚动到最顶部时下拉刷新. 图1,上拉刷新 图2,下拉刷新 1,设置lisview,加载heade ...
- jQuery模拟原生态App上拉刷新下拉加载
jQuery模拟原生态App上拉刷新下拉加载效果代码,鼠标上拉时会显示loading字样,并且会模拟加载一条静态数据,支持触屏设备使用. <!doctype html> <html ...
随机推荐
- M0 M4之GPIO初始化
新唐所有的M0/M4芯片基本上所有的IO都可以发生中断,为了符合大家的习惯还是有所谓的外部中断EINT0和EINT1.有2跟GPIO脚可以配置为EINT0功能和EINT1功能,分别将发生EINT0中断 ...
- 【Spring Boot && Spring Cloud系列】构建Springboot项目 实现restful风格接口
项目代码如下: package hello; import org.springframework.boot.SpringApplication; import org.springframework ...
- 禁止同一条ajax请求重复发出的方法
在项目中,遇到的问题是: 四个tab发送四个不同的请求,当用户连续在不同的按钮之间来回切换时,会出现不清楚那条数据是需要展示的的问题,和当连续点击同一个按钮时,基本同时返回的数据会全都展示出来的问题. ...
- Excel 中如何快速统计一列中相同字符的个数(函数法)
https://jingyan.baidu.com/article/6d704a132ea17328da51ca78.html 通过excel快速统计一列中相同字符的个数,如果很少,你可以一个一个数. ...
- Excel 2010 如何快速统计一列中相同数值出现的个数 很不错
https://jingyan.baidu.com/article/9113f81b2c16822b3214c785.html 最近经常看到论坛和百度知道的朋友提问关于“excel中如何快速统计一列中 ...
- postgresql----数据库表约束----FOREIGN KEY
六.FOREIGN KEY ---- 外键约束 外键可以是单个字段,也可以是多个字段.所谓的外键约束就是引用字段必须在被引用字段中存在,除非引用字段部分为NULL或全部为NULL(由MATCH TYP ...
- centos7 安装后,出现Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]
PS:出现以上信息,是要求你阅读或者接收协议: Initial setup of CentOS Linux 7 (core)解决步骤如下: 1,输入[1],按Enter键阅读许可协议,2,输入[2], ...
- 170504、MongoDB和MySQL对比(译)
一.概要 几十年来,关系型数据库已经成为企业应用程序的基础,自从MySQL在1995年发布以来,它已经成为一种受欢迎并且廉价的选择.然而随着近年来数据量和数据的不断激增,非关系数据库技术如MongoD ...
- django的framework优化
1.优化framework的性能,解决restapi调用慢的问题 ①预加载,关联查询时做缓存,序列化前简单调用setup_eager_loading ,这个需要确定sql查询调用情况(根据数据库结构确 ...
- Celery和Rabbitmq自学
异步消息队列,也能用于定时和周期性任务.每次修改的task代码还要重启worker,这个有点麻烦 所有带task()装饰器的可调用对象(usertask)都是celery.app.task.Task类 ...