You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.3 KiB

3 years ago
  1. /**
  2. * mescroll-more-item的mixins, 仅在多个 mescroll-body 写在子组件时使用 (参考 mescroll-more 案例)
  3. */
  4. const MescrollMoreItemMixin = {
  5. // 支付宝小程序不支持props的mixin,需写在具体的页面中
  6. // #ifndef MP-ALIPAY
  7. props:{
  8. i: Number, // 每个tab页的专属下标
  9. index: { // 当前tab的下标
  10. type: Number,
  11. default(){
  12. return 0
  13. }
  14. }
  15. },
  16. // #endif
  17. data() {
  18. return {
  19. downOption:{
  20. auto:false // 不自动加载
  21. },
  22. upOption:{
  23. auto:false // 不自动加载
  24. },
  25. isInit: false // 当前tab是否已初始化
  26. }
  27. },
  28. watch:{
  29. // 监听下标的变化
  30. index(val){
  31. if (this.i === val && !this.isInit) {
  32. this.isInit = true; // 标记为true
  33. this.mescroll && this.mescroll.triggerDownScroll();
  34. }
  35. }
  36. },
  37. methods: {
  38. // mescroll组件初始化的回调,可获取到mescroll对象 (覆盖mescroll-mixins.js的mescrollInit, 为了标记isInit)
  39. mescrollInit(mescroll) {
  40. this.mescroll = mescroll;
  41. this.mescrollInitByRef && this.mescrollInitByRef(); // 兼容字节跳动小程序
  42. // 自动加载当前tab的数据
  43. if(this.i === this.index){
  44. this.isInit = true; // 标记为true
  45. this.mescroll.triggerDownScroll();
  46. }
  47. },
  48. }
  49. }
  50. export default MescrollMoreItemMixin;