refreshBox.nvue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <refresh @refresh="refresh" @pullingdown="onpullingdown" :display="showRefresh ? 'show' : 'hide'">
  3. <view class="refreshBox">
  4. <!-- 可以自己添加图片路径或base64实现图片 <image class="refreshImg" :src="config[state].img" mode="widthFix" resize="cover"></image> -->
  5. <text class="refreshText">{{config[state].text}}</text>
  6. </view>
  7. </refresh>
  8. </template>
  9. <script>
  10. export default {
  11. data() {
  12. return {
  13. showRefresh:false, // 是否显示刷新
  14. state:0 // 刷新状态,0:继续下拉执行刷新,1:释放立即刷新,2:正在加载中,3:加载成功
  15. }
  16. },
  17. methods:{
  18. // 下拉刷新回调函数
  19. onpullingdown({pullingDistance,viewHeight}) {
  20. if(pullingDistance < viewHeight){
  21. this.state = 0 // 继续下拉执行刷新
  22. }else{
  23. this.state = 1 // 释放立即刷新
  24. }
  25. },
  26. // 执行刷新
  27. refresh(){
  28. // console.log('refresh');
  29. this.showRefresh = true // 显示刷新
  30. this.state = 2 // 正在加载中
  31. this.$emit('refresh') // 触发refresh事件
  32. }
  33. },
  34. watch: {
  35. // 监听loading变化
  36. loading(loading, oldValue) {
  37. if(!loading){
  38. this.showRefresh = false // 隐藏刷新
  39. this.state = 3 // 加载成功
  40. }
  41. }
  42. },
  43. props: {
  44. loading: {
  45. type:Boolean,
  46. default(){
  47. return false
  48. }
  49. },
  50. config: {
  51. type: Array,
  52. default(){
  53. return [
  54. {
  55. text:"继续下拉执行刷新",
  56. img:""//可以自己添加图片路径或base64实现图片
  57. },
  58. {
  59. text:"释放立即刷新",
  60. img:""//可以自己添加图片路径或base64实现图片
  61. },
  62. {
  63. text:"正在加载中",
  64. img:""//可以自己添加图片路径或base64实现图片
  65. },
  66. {
  67. text:"加载成功",
  68. img:""//可以自己添加图片路径或base64实现图片
  69. }
  70. ]
  71. }
  72. },
  73. },
  74. }
  75. </script>
  76. <style lang="scss" scoped>
  77. .refreshBox{
  78. width: 750rpx;
  79. height: 50px;
  80. justify-content: center;
  81. align-items: center;
  82. flex-direction: row;
  83. /* #ifndef APP-PLUS */
  84. margin-top: -50px;
  85. /* #endif */
  86. }
  87. .refreshImg{
  88. width: 55rpx;
  89. height: 55rpx;
  90. z-index: 111;
  91. }
  92. .refreshText{
  93. font-size: 26rpx;
  94. color: #999999;
  95. padding-left: 6rpx;
  96. }
  97. </style>