vue實現ajax滾動下拉載入,同時具有loading效果

來源:互聯網
上載者:User

標籤:介紹   viewport   max   ace   ext   auto   12px   doc   list   

<!doctype html><html><head><meta charset="utf-8"><title>vue測試ajax的使用</title><meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" /><style>*{ padding:0; margin:0}.list ul li{padding:10px 5px 10px 10px;overflow:hidden;zoom:1;position:relative;border-bottom:1px solid #e8e8e8;}.list ul li .img{margin-right:10px;display:block;width:60px;float:left;}.list ul li img{width:60px;height:60px;border-radius:8px;}.list ul li p{-webkit-box-flex:1;color:#777;overflow:hidden;padding-right:70px;}.list ul li p em{margin:7px 0;}.list ul li p a{display:block;height:16px;line-height:16px;overflow:hidden;font-size:15px;}.list ul li p span{display:block;line-height:16px;height:16px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font:12px "\5FAE\8F6F\96C5\9ED1";}.list ul li p u{margin:0 6px;padding:0 6px;border-left:1px solid #d9d9d9;border-right:1px solid #d9d9d9;}.list ul li .btn {width: 40px;height: 25px;padding-top: 35px;color: #65bb0a;line-height:25px;text-align:center;background: none;position:absolute;right:5px; top:12px}.list ul li .btn .bg {position: absolute;left: 0;top: 0;display: inline-block;width: 100%;height: 30px;repeat;background-size: 26px auto;}.get-more,.loading{display:block;padding:15px 0; line-height:16px;text-align:center;font-size:14px;}.loading{width:75px; margin:0 auto; background:url(imgs/loading.gif) 0 center no-repeat; padding-left:15px; background-size:13px auto}</style></head><body><div class="list" id="app" v-scroll="getMore">    <ul>        <li v-for="item in games">            <a v-bind:href="item.url" class="img"><img v-bind:src="item.img"></a>            <p>                <a v-bind:href="item.url">{{item.title}}</a>                <em class="lstar4"></em>                <span>{{item.server}}<u>39.9M</u>v2.1.3</span>            </p>            <a v-bind:href="item.url" class="btn"><em class="bg"></em>下載</a>        </li>    </ul>    <div>        <p class="get-more" v-on:click="getMore()" v-show="switchShow">點擊載入更多</p>        <p class="loading" v-show="!switchShow">載入中...</p>    </div></div><script src="js/vue.js"></script><script src="http://cdn.bootcss.com/vue-resource/1.0.3/vue-resource.min.js"></script><!--<script src="http://211.149.193.19:8090/vue-tutorials/04.OAuth/jquery-zepto/js/zepto.js"></script>--><script>var vm = new Vue({    el:‘#app‘,    data: {        url: ‘http://*******.com/dynamic.php?s=/Afs/ajaxHisTestServerData/cate_id/4/sta/‘,        nowPage: 0,        switchShow:false,        games: []    },    methods: {        moreFn: function (itemIndex) {            // console.log(this.nowPage)            this.$http.jsonp(this.url + itemIndex*10).then(function (response) {                this.games=this.games.concat(response.body);                this.switchShow=!this.switchShow;              }, function (response) {                  console.log(response)            });                    },        getMore: function () {            this.switchShow=!this.switchShow;            this.nowPage++;            this.moreFn(this.nowPage);        },        init: function () {            this.moreFn(this.nowPage);        }    },    directives: {// 自訂指令      scroll: {        bind: function (el, binding){          window.addEventListener(‘scroll‘, function () {            if(document.body.scrollTop + window.innerHeight >= el.clientHeight) {              var fnc = binding.value;                 fnc();             }          })        }      }    }})vm.init();</script></body></html>

 功能介紹:

1.vue進行ajax請求載入;

2.實現滾動,點擊載入資料;

3.通過自訂實現loading 效果;

痛點:

1.需要官方的vue-resource組件,進行ajax請求,所以需要瞭解該API;

2.loading,通過v-show進行判斷顯示不同的loading 效果;

3.自訂指令,也是最痛點,所以需要瞭解基本的自訂指令API;

 

vue實現ajax滾動下拉載入,同時具有loading效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.