vue-infinite-loading2.0 中文文档详解

2020-06-13 10:16:13易采站长站整理

min-height: 455px;
background-color: #f6f6ef;
}
.hacker-news-list .hacker-news-header select {
float: right;
color: #fff;
background-color: transparent;
border: 1px solid #fff;
outline: none;
}

<p id=”server”>服务端渲染</p>

服务端渲染(SSR)是<strong>Vue.js2.0</strong>的新特性,当你在你的SSR应用中使用这个组件,会得到类似这样的错误:


Error: window is not defined
ReferenceError: window is not defined
at ...
at ...
at e.exports (...)
at Object. (...)
at p (...)
at Object.e.exports.render.e (...)
at p (...)
at Object. (...)
at p (...)
at e.__esModule.default (...)

因为<strong>style-loader</strong>不支持在这个时候本地导出,详情点这里,所以我们需要下面的变通方案,为了你的SSR应用:


import InfiniteLoading from 'vue-infinite-loading/src/components/Infiniteloading.vue';

代替


import InfiniteLoading from 'vue-infinite-loading';

<strong>npm install less less-loader –save-dev</strong> 如果你还没有安装它们。

然后你的SSR应用应该运行良好。如果不是,你可以加入这个issue去讨论。

<p id=”properties”>属性<p>

on-infinite

这是一个回调函数,当滚动到距离滚动父元素底部特定距离的时候,会被调用。

通常,在数据加载完成后,你应该在这个函数中发送<strong>$InfiniteLoading:loaded</strong>事件。


- type Function
- reuqired true

distance

这是滚动的临界值。如果到滚动父元素的底部距离小于这个值,那么<strong>on-infinite</strong>回调函数就会被调用。


- type Number
- required false
- default 100
- unit pixel

spinner

通过这个属性,你可以选择一个你最喜爱旋转器作为加载动画。点击这里可以看到所有可用的旋转器。


- type String
- required false
- default 'default'

ref

正如你所知,这个属性是一个Vue.js的官方指令,用来获取子组件的实例。我们需要用它来得到<strong> InfiniteLoading </strong>组件的实例来发送事件。你可以用这种方式来得到实例:<strong>this.$refs[the value of ref attribute].</strong>


- type String