AlertZMK
AlertZMK
  • 发布:2018-01-01 22:36
  • 更新:2018-01-04 15:55
  • 阅读:1341

【求源码解析】pullRefresh()方法为什么能实现scroll()初始化功能

分类:MUI

看了一下pullRefresh的源码,发现好像没有调用scroll()的方法
pullRefresh的几个init
mui.init pulldownRefresh

init: function(element, options) {  
            this._super(element, $.extend(true, {  
                scrollY: true,  
                scrollX: false,  
                indicators: true,  
                deceleration: 0.003,  
                down: {  
                    height: 50,  
                    contentinit: '下拉可以刷新',  
                    contentdown: '下拉可以刷新',  
                    contentover: '释放立即刷新',  
                    contentrefresh: '正在刷新...'  
                },  
                up: {  
                    height: 50,  
                    auto: false,  
                    contentinit: '上拉显示更多',  
                    contentdown: '上拉显示更多',  
                    contentrefresh: '正在加载...',  
                    contentnomore: '没有更多数据了',  
                    duration: 300  
                }  
            }, options));  
        },  
        _init: function() {  
            this._super();  
            this._initPocket();  
        },

pullRefresh 5+

init: function(element, options) {  
                this.element = element;  
                this.options = options;  
                this.wrapper = this.scroller = element;  
                this._init();  
                this._initPulldownRefreshEvent();  
            },  
            _init: function() {  
                var self = this;  
                //document.addEventListener('plusscrollbottom', this);  
                window.addEventListener('dragup', self);  
                document.addEventListener("plusscrollbottom", self);  
                self.scrollInterval = window.setInterval(function() {  
                    if (self.isScroll && !self.loading) {  
                        if (window.pageYOffset + window.innerHeight + 10 >= document.documentElement.scrollHeight) {  
                            self.isScroll = false; //放在这里是因为快速滚动的话,有可能检测时,还没到底,所以只要有滚动,没到底之前一直检测高度变化  
                            if (self.bottomPocket) {  
                                self.pullupLoading();  
                            }  
                        }  
                    }  
                }, 100);  
            },

想给pullRefresh添加一个和scroll().destroy()方法,应该怎么加?

2018-01-01 22:36 负责人:无 分享
已邀请:
AlertZMK

AlertZMK (作者)

打开了二层的proto
找到了scroll()相关的api,所以pullRefresh()继承自scroll()方法,我尝试调用这个destroy()方法,报错

Uncaught TypeError: Cannot read property 'removeEventListener' of undefined  
    at Class._initEvent (mui.js?0540:3827)  
    at Class.destroy (mui.js?0540:4385)  
    at VueComponent.refreshScroll (App.vue?ea99:238)  
    at VueComponent.boundFn [as refreshScroll] (vue.esm.js?efeb:190)  
    at eval (App.vue?ea99:365)

请问大佬们,我应该怎么调用destroy()才能做到把pullRefresh()生成的scroll去掉呢?

DCloud_UNI_FXY

DCloud_UNI_FXY

在mui.class.scroll.pullrefresh.js中增加destroy方法

 destroy: function () {  
      this._super();  

      if (this.bottomPocket) {  
        this.bottomPocket.parentNode.removeChild(this.bottomPocket);  
      }  
      if (this.topPocket) {  
        this.topPocket.parentNode.removeChild(this.topPocket);  
      }  

      if (this.indicators) {  
        for (var i = this.indicators.length; i--;) {  
          var indicatorElem = this.indicators[i].wrapper;  
          indicatorElem.parentNode.removeChild(indicatorElem);  
        }  
      }  

      delete $.data[this.wrapper.getAttribute('data-pullrefresh')];  
      this.wrapper.removeAttribute('data-pullrefresh');  
    }

该问题目前已经被锁定, 无法添加新回复