refreshBox.nvue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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
  15. }
  16. },
  17. methods:{
  18. onpullingdown({pullingDistance,viewHeight}) {
  19. if(pullingDistance < viewHeight){
  20. this.state = 0
  21. }else{
  22. this.state = 1
  23. }
  24. },
  25. refresh(){
  26. // console.log('refresh');
  27. this.showRefresh = true
  28. this.state = 2
  29. this.$emit('refresh')
  30. }
  31. },
  32. watch: {
  33. loading(loading, oldValue) {
  34. if(!loading){
  35. this.showRefresh = false
  36. this.state = 3
  37. }
  38. }
  39. },
  40. props: {
  41. loading: {
  42. type:Boolean,
  43. default(){
  44. return false
  45. }
  46. },
  47. config: {
  48. type: Array,
  49. default(){
  50. return [
  51. {
  52. text:"继续下拉执行刷新",
  53. img:""//可以自己添加图片路径或base64实现图片
  54. },
  55. {
  56. text:"释放立即刷新",
  57. img:""//可以自己添加图片路径或base64实现图片
  58. },
  59. {
  60. text:"正在疯狂的加载中",
  61. img:""//可以自己添加图片路径或base64实现图片
  62. },
  63. {
  64. text:"加载成功",
  65. img:""//可以自己添加图片路径或base64实现图片
  66. }
  67. ]
  68. }
  69. },
  70. },
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. .refreshBox{
  75. width: 750rpx;
  76. height: 50px;
  77. justify-content: center;
  78. align-items: center;
  79. flex-direction: row;
  80. /* #ifndef APP-PLUS */
  81. margin-top: -50px;
  82. /* #endif */
  83. }
  84. .refreshImg{
  85. width: 55rpx;
  86. height: 55rpx;
  87. z-index: 111;
  88. }
  89. .refreshText{
  90. font-size: 26rpx;
  91. color: #999999;
  92. padding-left: 6rpx;
  93. }
  94. </style>