bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

vue中實現滾動加載更多的示例

在以前的前端刀耕火種時代要實現滾動加載更多想要大家都是很快實現了,在vue會有一點麻煩,最近自己研究了一下,做了一個簡單的demo,供大家參考:

成都創新互聯公司2013年至今,是專業互聯網技術服務公司,擁有項目做網站、網站制作網站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元宜豐做網站,已為上家服務,為宜豐各地企業和個人服務,聯系電話:18982081108

<template>
  <div>
    <ul>
      <li v-for="item in articles">
        <h3>{{item.title}}</h3>
        <img :src="item.images" alt="">
      </li>
    </ul>
  </div>
</template>
<script>
  import axios from 'axios';
  export default{
    data(){
      return {
        articles : []
      }
    },
    mounted(){
      // 緩存指針
      let _this = this;
      // 設置一個開關來避免重負請求數據
      let sw = true;
      // 此處使用node做了代理
      axios.get('http://localhost:3000/proxy?url=http://news-at.zhihu.com/api/4/news/latest')
        .then(function(response){
          // console.log(JSON.parse(response.data).stories);
          // 將得到的數據放到vue中的data
          _this.articles = JSON.parse(response.data).stories;
        })
        .catch(function(error){
          console.log(error);
        });

      // 注冊scroll事件并監聽
      window.addEventListener('scroll',function(){
        // console.log(document.documentElement.clientHeight+'-----------'+window.innerHeight); // 可視區域高度
        // console.log(document.body.scrollTop); // 滾動高度
        // console.log(document.body.offsetHeight); // 文檔高度
        // 判斷是否滾動到底部
        if(document.body.scrollTop + window.innerHeight >= document.body.offsetHeight) {
          // console.log(sw);
          // 如果開關打開則加載數據
          if(sw==true){
            // 將開關關閉
            sw = false;
            axios.get('http://localhost:3000/proxy?url=http://news.at.zhihu.com/api/4/news/before/20170608')
              .then(function(response){
                console.log(JSON.parse(response.data));
                // 將新獲取的數據push到vue中的data,就會反應到視圖中了
                JSON.parse(response.data).stories.forEach(function(val,index){
                  _this.articles.push(val);
                  // console.log(val);
                });
                // 數據更新完畢,將開關打開
                sw = true;
              })
              .catch(function(error){
                console.log(error);
              });  
          }
        }
      });
    }
  }
</script>
<style lang="less">
  *{
    margin:0;
    padding:0;
  }
  li{
    list-style:none;
  }
</style>

大致效果如下

vue中實現滾動加載更多的示例

當然目前只是一個demo,還有更好的解決辦法大家自行補充。

以上這篇vue中實現滾動加載更多的示例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持創新互聯。

網頁標題:vue中實現滾動加載更多的示例
路徑分享:http://vcdvsql.cn/article32/iigjpc.html

成都網站建設公司_創新互聯,為您提供用戶體驗面包屑導航虛擬主機靜態網站App開發全網營銷推廣

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都定制網站網頁設計