码迷,mamicode.com
首页 > 其他好文 > 详细

vue插件vue-infinite-loading的使用

时间:2018-06-06 22:18:42      阅读:1344      评论:0      收藏:0      [点我收藏+]

标签:efault   limit   length   ade   页面   over   import   AC   lse   

vue-infinite-loading官网:https://peachscript.github.io/vue-infinite-loading/ 
安装:

npm install vue-infinite-loading --save

  

list.vue页面

<template>
    <div class="list-con">
        <div class="list" v-for="(item,key) in list">
            <span v-text="key+1"></span>
            <p>
                <a :href="item.url">{{item.title}}</a>
            </p>
        </div>
        <infinite-loading :on-infinite="onInfinite" ref="infiniteLoading">
           <span slot="no-more">没有更多消息了</span>
        </infinite-loading>
    </div>
</template>
<script>
import InfiniteLoading from ‘vue-infinite-loading‘;
const api = ‘http://hn.algolia.com/api/v1/search_by_date?tags=story‘;
export default {
    components: {
        InfiniteLoading,
    },
    data() {
        return {
            list: []
        }
    },
    mounted: function() {

    },
    methods: {

        onInfinite() {
            let params = {
                page: this.list.length / 20 + 1
            }
            this.$http.get(api, params).then((res) => {
                if (res.data.hits.length) {
                    this.list = this.list.concat(res.data.hits);
                    this.$refs.infiniteLoading.$emit(‘$InfiniteLoading:loaded‘);
                    if (this.list.length / 20 === 10) {
                        this.$refs.infiniteLoading.$emit(‘$InfiniteLoading:complete‘);
                    }
                } else {
                    this.$refs.infiniteLoading.$emit(‘$InfiniteLoading:complete‘);
                }
            })
        }
    }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .list{
    overflow:hidden;
    margin:20px 0;
  }
  span{
    float: left;
    margin-right: 5px;
  }
  p{
    float: left;
  }
</style>

vue插件vue-infinite-loading的使用

标签:efault   limit   length   ade   页面   over   import   AC   lse   

原文地址:https://www.cnblogs.com/wntd/p/9146567.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!