Home > Web Front-end > JS Tutorial > vue.js loads new content

vue.js loads new content

巴扎黑
Release: 2017-06-26 15:02:51
Original
1392 people have browsed it

Vue is a lightweight and convenient framework, so how to refresh the data loading? The following are my thoughts on vue.js data loading

Source code:


 

      

  •    

      

  •  

  

  

Loading...


  
  

Analysis:

$(function() {
  var pageNum = 1;
var pageSize = 6;
vue = new Vue({
el: '#app',
data: {
items: [],
pageNum: pageNum,
pageSize: pageSize,
rawItems: [],
sitems:[]
},
methods: {
getList: function() {
$.showLoading();
     this.$http.get(store.list, {
      pageNum: pageNum,
    pageSize: pageSize
   }).then(function(result) {
    $.removeLoading();
    this.sitems = result.data.data.items;
   }, function() {
    $.removeLoading();
    $.showAlert({
     'title': 'Tips' ,
      'content': "The page is lazy~~",
      'sure': this.close
     });
    })
  },
  close: function() {
   history.go(-1);
  },
  onScroll: function(event) {
   var offsetHeight = event.currentTarget.offsetHeight,
  scrollHeight = event.target.scrollHeight,
  scrollTop = event.target.scrollTop,
  scrollBottom = offsetHeight + scrollTop;
  if(scrollBottom == scrollHeight+10 ||scrollBottom == scrollHeight) {
  if(this.pageNum == Math .ceil(this.rawItems.length / this.pageSize)) {
    return
    }
   this.pageNum++;
   pageNum++;
   $(".myload").removeClass("disn ");
    vue.$http.get(store.list, {
      pageNum: pageNum,
     pageSize: pageSize
    }).then(function(result) {
     setTimeout(function () {
      $(".myload").addClass("disn");
      vue.sitems = vue.sitems.concat(result.data.data.items);
     }, 2000)
    }, function() {
    $(".myload").addClass("disn");
    })
    }
   },
  },
  ready : function() {
   this.getList();
   for(var i = 0; i <= 1000; i++) {
     this.rawItems.push(i)
   }
  }
  })
})

The above is the detailed content of vue.js loads new content. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template