基于Vue框架vux组件库实现上拉刷新功能
程序员文章站
2022-07-06 19:39:20
最近公司在研发app,选择了基于vue框架的vux组件库,现总结在实现上拉刷新功能遇到的坑:
1.问题:只刷新一次,解决方法:需要自己手动重置状态
this.scr...
最近公司在研发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>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。