file.vue
<template>
<v-btn color="primary" @click="loadMore">
load more
</v-btn></div>
</template>
<script>
export default {
methods: {
loadMore() {
this.$store.dispatch('getAllProducts', {
limit: this.products.length + 8
})
}
},
created() {
this.$store.dispatch('getAllProducts', {
limit: 8
})
}
actions.js
getAllProducts({commit},payload){
return new Promise((resolve, reject) => {
return api.get(`product.json?orderBy="$key"&limitToLast=${payload.limit}`)
.then(res => res.data)
.then(res => {
const products = []
for (let key in res) {
if (res.hasOwnProperty(key)) {
products.push({
...res[key],
id: key
})
}
}
commit('getAllProducts',products.reverse())
resolve(res)
console.log(res)
})
.catch(err => {
reject(err)
console.log(err)
})
})
},
استعملت هذي الطريقة سابقا لتحميل المزيد من النتائج.
ابحث الان عن طريقة ربط pagination الخاصة بـ vuetify مع firebase realtime
استعملت عدة طرق لكن لم تعمل, رجعت الان للبداية :
<template>
<div class="text-center">
<v-pagination
v-model="pagination.page"
:length="pagination.total / 8"
:total-visible="pagination.visible"
></v-pagination>
</div>
</template>
<script>
export default {
data() {
return {
pagination: {
page: 1,
total: 0,
perPage: 0,
visible: 7
}
}
},
created() {
this.$store.dispatch('getAllProducts', {
limit: 8
})
.then(res => {
let products = []
for (let key in res) {
if (res.hasOwnProperty(key)) {
products.push({
...res[key],
id: key
})
}
}
this.pagination.total = products.length
})
}
}
هل من الممكن انها لا تعمل الا في firestore ؟