vue에서 백엔드 데이터 가져오고 페이지 나누기

2994 단어


var _this;
export default {
  name: 'daohang',
  data () {
    return {
      list: [],
      currentPage: 1,//   
      pageSize: 20,
      is_extending: true
    }
  },
  created () {
    _this = this
    _this.getdata()
  },
  mounted () {
    window.addEventListener('scroll', this.menu)
  },
  methods: {
    getdata () {
      $.ajax({
        type: "GET",
        url: " ",//    
        contentType: 'application/x-www-form-urlencoded;charset=utf-8',
        data: {
          user_id: 666,
          currentPage: 1,
          pageSize: 20
        },
        success: function (data) {
          if (data.err_code > 0) {
            alert(data.err_msg)
            _this.is_extending = false;
          } else {
            _this.list = data.data
          }
          console.log(data.data)
        }
      });
    },
    refgetdata () {
      _this.currentPage = _this.currentPage + 1;
      console.log(_this.currentPage);
      $.ajax({
        type: "GET",
        url: " ",//    
        contentType: 'application/x-www-form-urlencoded;charset=utf-8',
        data: {
          user_id: 666,
          page: _this.currentPage,
          pageSize: 20
        },
        success: function (data) {
          if (data.err_code > 0) {
            alert(data.err_msg)
            _this.is_extending = false;
          } else {
            if (_this.currentPage * _this.pageSize <= data._meta.totalCount + 20) {
              _this.list = _this.list.concat(data.data);
              _this.is_extending = true;
            }
            else {
              _this.$toast('     ', { duration: 3000 });
            }

          }
          console.log(data.data)
        }
      });
    },
    menu: function () {
      // //       
      // var pageHeight = Math.max(document.body.scrollHeight, document.body.offsetHeight);
      // //     
      // var viewportHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0;
      // //     
      // var scrollHeight = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
      // //        ,  
      // if (pageHeight - viewportHeight - scrollHeight < 10) {
      //   this.refgetdata();//    
      // }
      var _this = this;
      _this.scroll = document.documentElement.scrollTop || document.body.scrollTop;
      if (_this.scroll + window.innerHeight + 20 >= document.documentElement.offsetHeight) {
        if (_this.is_extending) {
          _this.is_extending = false;
          _this.refgetdata();
        }

      }
    }
  }
}


좋은 웹페이지 즐겨찾기