基于Vue框架vux组件库实现上拉刷新功能


Posted in Javascript onNovember 28, 2017

最近公司在研发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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
判断控件是否已加载完成的代码
Feb 24 Javascript
jQuery中:file选择器用法实例
Jan 04 Javascript
jQuery检测滚动条是否到达底部
Dec 15 Javascript
gulp-htmlmin压缩html的gulp插件实例代码
Jun 06 Javascript
轻松掌握JavaScript单例模式
Aug 25 Javascript
微信小程序实现循环动画效果
Jul 16 Javascript
在react中使用vuex的示例代码
Jul 30 Javascript
Vue+Express实现登录状态权限验证的示例代码
May 05 Javascript
基于JS抓取某高校附近共享单车位置 使用web方式展示位置变化代码实例
Aug 27 Javascript
Vuejs中的watch实例详解(监听者)
Jan 05 Javascript
vue-video-player视频播放器使用配置详解
Oct 23 Javascript
解决antd datepicker 获取时间默认少8个小时的问题
Oct 29 Javascript
JavaScript中关于class的调用方法
Nov 28 #Javascript
基于vue+canvas的excel-like组件实例详解
Nov 28 #Javascript
JS原型继承四步曲及原型继承图一览
Nov 28 #Javascript
weebox弹出窗口不居中显示的解决方法
Nov 27 #Javascript
Dropify.js图片宽高自适应的方法
Nov 27 #Javascript
jfinal与bootstrap的登出实战详解
Nov 27 #Javascript
JQuery 又谈ajax局部刷新
Nov 27 #jQuery
You might like
开源SNS系统-ThinkSNS
2008/05/18 PHP
smarty模板中使用get、post、request、cookies、session变量的方法
2014/04/24 PHP
ThinkPHP关于session的操作方法汇总
2014/07/18 PHP
浅谈PHP值mysql操作类
2016/06/29 PHP
ThinkPHP5.1的权限控制怎么写?分享一个AUTH权限控制
2021/03/09 PHP
JavaScript里实用的原生API汇总
2015/05/14 Javascript
JavaScript获取css行间样式,内连样式和外链样式的简单方法
2016/07/18 Javascript
JS实现HTML表格排序功能
2016/08/05 Javascript
Vue2 Vue-cli中使用Typescript的配置详解
2017/07/24 Javascript
element-ui 表格数据时间格式化的方法
2018/08/24 Javascript
Javascript之高级数组API的使用实例
2019/03/08 Javascript
vue组件定义,全局、局部组件,配合模板及动态组件功能示例
2019/03/19 Javascript
[04:00]DOTA2解说界神雕侠侣 CJ第四天谷子现场过生日
2013/07/30 DOTA
[00:33]DOTA2上海特级锦标赛 CDEC战队宣传片
2016/03/04 DOTA
python实现udp数据报传输的方法
2014/09/26 Python
浅谈Python中copy()方法的使用
2015/05/21 Python
Python网络爬虫项目:内容提取器的定义
2016/10/25 Python
python3 requests中使用ip代理池随机生成ip的实例
2018/05/07 Python
使用python PIL库实现简单验证码的去噪方法步骤
2019/05/10 Python
Django Docker容器化部署之Django-Docker本地部署
2019/10/09 Python
Pytorch 多块GPU的使用详解
2019/12/31 Python
python爬虫开发之selenium模块详细使用方法与实例全解
2020/03/09 Python
Python多线程正确用法实例解析
2020/05/30 Python
cookies应对python反爬虫知识点详解
2020/11/25 Python
Notino意大利:购买香水和化妆品
2018/11/14 全球购物
给同事的道歉信
2014/01/11 职场文书
员工薪酬福利制度
2014/01/17 职场文书
村长贪污检举信
2014/04/04 职场文书
小学生关于梦想的演讲稿
2014/08/22 职场文书
幼儿园门卫安全责任书
2015/05/08 职场文书
士兵突击观后感
2015/06/16 职场文书
接收函
2019/04/22 职场文书
应届生个人的求职(自荐信范文2篇)
2019/08/23 职场文书
Python 居然可以在 Excel 中画画你知道吗
2022/02/15 Python
直播实况, OMG破敌三路五十分钟大战神技局摩托车
2022/04/01 DOTA
macos系统如何实现微信双开? mac登录两个微信以上微信的技巧
2022/07/23 数码科技