Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

u-infinite-scroll.vue

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

u-infinite-scroll.vue

<!-- 该 README.md 根据 api.yaml 和 docs/*.md 自动生成,为了方便在 GitHub 和 NPM 上查阅。如需修改,请查看源文件 -->

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

UInfiniteScroll 无限滚动

示例

UInfiniteScroll 无限滚动

无限下拉滚动加载组件

<template>
    <div infinite-scroll-container :class="$style.container">
        <u-infinite-scroll
            :step="step"
            :lazyRows="lazyRows"
            :normalizeData="normalizeData"
            :getDefaultData="getDefaultData"
            :loadmoreFn="loadmoreFn">
            <template slot-scope="{ displayData }">
                <div v-if="displayData.length > 0" v-for="(d, idx) in displayData" :key="d.timestamp">
                    {{d.timestamp}} : {{ d.message }}
                </div>
            </template>
        </u-infinite-scroll>
    </div>
</template>
<script>
function getRandomLengthString(p , min, max){
    return p.repeat(min + (Math.floor(Math.random()*(max - min))))
}
let now = 0;
function getRandomData(){
    return {
        timestamp: now ++,
        message: getRandomLengthString('s', 20, 30),
    }
}
let fake = 0
function getRandomDefaultData(){
    return {
        timestamp: 'f' + (fake++),
        message: getRandomLengthString('l', 20, 30),
    }
}
export default {
    data() {
        return {
            step: 50,
            lazyRows: 10,
        }
    },
    methods: {
        normalizeData(data){
            return data
        },
        getDefaultData(){
            return getRandomDefaultData()
        },
        loadmoreFn(){
            const step = this.step;
            return new Promise(r => {
                setTimeout(() => {
                    r({
                        total: 200,
                        hits: new Array(step).fill(1).map(getRandomData),
                    })
                }, 1000 + Math.floor(Math.random(3000))) 
            })

        }
    }
}
</script>
<style module>
.container{
    height: 200px;
    overflow: scroll;
}
</style>

API

Props/Attrs

Prop/AttrTypeOptionsDefaultDescription
stepnumber数据每次加载的条数
lazyRowsnumber10数据每次渲染的条数
normalizeDatafunction数据整理函数 data => data
getDefaultDatafunction数据未加载出来时的站位数据
loadmoreFnfunction加载函数,需要返回一个Promise对象,对象返回 total 和 hits 数据

Slots

(default)

插入文本或 HTML。

Keywords

FAQs

Package last updated on 16 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc