import Vue from 'vue';

Vue.directive('loadmore', {
  bind (el, binding) {
    // 获取element-ui定义好的scroll盒子
    const SELECTWRAP_DOM = el.querySelector('.scroll-box');
    console.log(SELECTWRAP_DOM);
    let flag = true, timeoutId = null;
    SELECTWRAP_DOM.addEventListener('scroll', function () {
      // console.log(this.scrollHeight, this.scrollTop, this.clientHeight);
      const CONDITION = this.scrollTop == 0;
      if (CONDITION) {
        if(flag) {
          flag = false;
          timeoutId && clearTimeout(timeoutId);
          timeoutId = setTimeout( () => {
            binding.value();
            flag = true;
          }, 150);
        }
      }
    });
  }
});