tnblog
首页
视频
资源
登录

scroll-view封裝刷新加载组件

4016人阅读 2022/3/9 19:06 总访问:69738 评论:0 收藏:0 手机
分类: uinapp
  1. <template>
  2. <view class="container">
  3. <scroll-view scroll-with-animation class="scroll" :class="class1" :scroll-y="scrollY" :scroll-top="scrollTop" 
  4. :refresher-enabled="isrefresh" :refresher-threshold="refresherThreshold" 
  5. :refresher-triggered="triggered" @refresherrefresh="onRefresh" :refresher-default-style="rstyle"
  6. :refresher-background="rsback"
  7. @scrolltolower="scrolltolower" @scrolltoupper="scrolltoupper" @scroll="scroll"
  8. >
  9. <slot></slot>
  10. </scroll-view>
  11. </view>
  12. </template>
  1. <script>
  2. export default {
  3. name"container",
  4. props: {
  5. scrollTop: {
  6. typeNumber,
  7. default0
  8. },
  9. isrefresh: {
  10. typeBoolean,
  11. defaultfalse
  12. },
  13. refresherThreshold:{
  14. typeNumber,
  15. default45
  16. },
  17. isend:{
  18. typeBoolean,
  19. defaultfalse
  20. },
  21. scrollY:{
  22. typeBoolean,
  23. defaulttrue
  24. },
  25. rstyle:{
  26. type:String,
  27. default:'black'
  28. },
  29. rsback:{
  30. type:String,
  31. default:'#ffffff'
  32. },
  33. class1:{
  34. type:String,
  35. default:''
  36. }
  37. },
  38. data() {
  39. return {
  40. Isfreshing:false,
  41. triggered:false,
  42. }
  43. },
  44. methods: {
  45. onRefresh(data) {   //刷新
  46.     if (this.Isfreshing) return;  
  47. this.Isfreshing = true;  
  48. if (!this.triggered)//保证刷新状态下,triggered为true  
  49. this.triggered = true;
  50. this.$emit("onRefresh", data)
  51. setTimeout(() => {
  52.         this.triggered = false
  53.         this.Isfreshing = false;
  54. this.onRestore(); //触发onRestore,关闭刷新图标 
  55.     }, 1200)  
  56. },
  57. onRestore(data) {   // 需要重置
  58. this.$emit("onRestore", data)
  59. },
  60. scrolltolower(data) {  //到底
  61. this.$emit("scrolltolower", data)
  62. },
  63. scrolltoupper(data){  //到顶
  64. this.$emit("scrolltoupper", data)
  65. },
  66. scroll(data) {  //滚动
  67. this.$emit("scroll", data)
  68. },
  69. }
  70. }
  71. </script>
  1. <style>
  2. .container {
  3. position: relative;
  4. display: flex;
  5. width100%;
  6. flex-shrink1;
  7. flex-grow1;
  8. z-index1;
  9. .scroll {
  10. position: absolute;
  11. top0;
  12. right0;
  13. bottom0;
  14. left0;
  15. }
  16. }
  17. </style>


使用组件

<container @scroll="scroll" @scrolltolower="loadMore" @onRestore="refresh" :isrefresh="true" :scroll-y="true" rsback="#ffffff"></container>





评价
走投无路 才选择了程序员
排名
40
文章
11
粉丝
3
评论
0
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术