综合办公系统
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <!-- 菜单悬浮的原理: 通过给菜单添加position:sticky实现, 用法超简单, 仅APP端的低端机不兼容 https://caniuse.com/#feat=css-sticky -->
  2. <template>
  3. <view>
  4. <!-- 对于mescroll-body: 需设置:sticky="true", 此应避免在mescroll-body标签前面加其他非定位的元素, 否则下拉区域会被挤出, 无法会隐藏.-->
  5. <!-- 对于mescroll-uni: 则无需设置:sticky="true", 无其他限制和要求 -->
  6. <mescroll-body :sticky="true" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
  7. <swiper style="min-height: 300rpx" autoplay="true" interval="3000" duration="300" circular="true">
  8. <swiper-item>
  9. <image style="width: 100%;height: auto;" src="https://www.mescroll.com/img/swiper1.jpg" mode="widthFix"/>
  10. </swiper-item>
  11. <swiper-item>
  12. <image style="width: 100%;height: auto;" src="https://www.mescroll.com/img/swiper2.jpg" mode="widthFix"/>
  13. </swiper-item>
  14. </swiper>
  15. <view class="demo-tip">
  16. <view>每次切换菜单,都刷新列表数据</view>
  17. <view>吸顶通过给菜单加position:sticky实现, 用法简单</view>
  18. <view>小程序和微信h5端: 低端机sticky也可生效, 可放心使用</view>
  19. <view>APP端: 仅部分低端机无效,若要兼容则参考sticky-scroll</view>
  20. </view>
  21. <!-- sticky吸顶悬浮的菜单, 父元素必须是 mescroll -->
  22. <view class="sticky-tabs">
  23. <me-tabs v-model="tabIndex" :tabs="tabs" @change="tabChange"></me-tabs>
  24. </view>
  25. <!-- 数据列表 -->
  26. <good-list :list="goods"></good-list>
  27. </mescroll-body>
  28. <!-- 此处可以写其他fixed定位元素 -->
  29. <!-- <view></view> -->
  30. </view>
  31. </template>
  32. <script>
  33. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  34. import {apiSearch} from "@/api/mock.js"
  35. export default {
  36. mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
  37. data() {
  38. return {
  39. goods: [], // 数据列表
  40. tabs: ['全部', '母婴', '图书'],
  41. tabIndex: 0 // tab下标
  42. }
  43. },
  44. methods: {
  45. /*下拉刷新的回调 */
  46. downCallback() {
  47. // 这里加载你想下拉刷新的数据, 比如刷新轮播数据
  48. // loadSwiper();
  49. // 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  50. this.mescroll.resetUpScroll()
  51. },
  52. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  53. upCallback(page) {
  54. let keyword = this.tabs[this.tabIndex]
  55. apiSearch(page.num, page.size, keyword).then(curPageData=>{
  56. if(page.num == 1) this.goods = []; //如果是第一页需手动制空列表
  57. this.goods=this.goods.concat(curPageData); //追加新数据
  58. this.mescroll.endSuccess(curPageData.length); // 隐藏加载状态栏
  59. }).catch(()=>{
  60. //联网失败, 结束加载
  61. this.mescroll.endErr();
  62. })
  63. },
  64. // 切换菜单
  65. tabChange () {
  66. this.goods = []; // 置空列表,显示加载进度条
  67. this.mescroll.resetUpScroll()
  68. }
  69. }
  70. }
  71. </script>
  72. <style lang="scss">
  73. /*
  74. sticky生效条件:
  75. 1、父元素不能overflow:hidden或者overflow:auto属性。(mescroll-body设置:sticky="true"即可, mescroll-uni本身没有设置overflow)
  76. 2、必须指定top、bottom、left、right4个值之一,否则只会处于相对定位
  77. 3、父元素的高度不能低于sticky元素的高度
  78. 4、sticky元素仅在其父元素内生效,所以父元素必须是 mescroll
  79. */
  80. .sticky-tabs{
  81. z-index: 990;
  82. position: sticky;
  83. top: var(--window-top);
  84. background-color: #fff;
  85. }
  86. // 使用mescroll-uni,则top为0
  87. .mescroll-uni,
  88. /deep/.mescroll-uni{
  89. .sticky-tabs{
  90. top: 0;
  91. }
  92. }
  93. .demo-tip{
  94. padding: 18rpx;
  95. font-size: 24rpx;
  96. text-align: center;
  97. }
  98. </style>