【发布时间】:2019-04-21 09:52:46
【问题描述】:
问题:如何在不重新查询之前检索(和绑定)的结果的情况下向绑定的 Firestore VuexFire 引用添加分页(无限滚动)?
背景: 我目前正在使用 VuexFire firestore 绑定来填充大多数被投票的帖子的时间线,作为一项操作,在我的 Vuex 商店中,如下所示:
fillTimeLine: firebaseAction(
({ bindFirebaseRef }) => {
bindFirebaseRef(
'timelineResults',
db
.collection('POSTS')
.orderBy('combined_vote_score', 'desc')
.limit(30)
)
})
这会将我的 firestore 数据库中评分最高的前 30 个帖子检索到我的 vuex 状态变量timelineResults。
要添加分页,我发现了一个非 VuexFire 示例,如下所示: How to paginate or infinite scroll by number of items in firestore?
var first = db.collection("....").orderBy("price", "desc").limitTo(20);
return first.get().then(function (documentSnapshots) {
// Get the last visible document
var lastVisible = documentSnapshots.docs[documentSnapshots.docs.length-1];
console.log("last", lastVisible);
// Construct a new query starting at this document,
// get the next 25 cities.
var next = db.collection("....")
.orderBy("price", "desc")
.startAfter(lastVisible)
.limit(20);
});
有没有办法将这两个示例结合起来并将结果附加到绑定的引用中?
【问题讨论】:
-
你实现了吗?
标签: vue.js pagination google-cloud-firestore vuex vuexfire