Pagination > infinite scroll, page routing
This commit is contained in:
parent
16f5ee9de7
commit
2234c2304a
4 changed files with 38 additions and 16 deletions
|
@ -61,7 +61,7 @@ export default {
|
||||||
],
|
],
|
||||||
methods: {
|
methods: {
|
||||||
openSpell (event) {
|
openSpell (event) {
|
||||||
console.log(this.spell.name)
|
this.$router.push('/spell/' + this.spell.name)
|
||||||
},
|
},
|
||||||
toggle (want) {
|
toggle (want) {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
|
|
@ -1,21 +1,23 @@
|
||||||
<template>
|
<template>
|
||||||
<section
|
<section class="spell-list list striped no-border" id="spell_list">
|
||||||
is="q-infinite-scroll"
|
|
||||||
:handler="loadMore"
|
|
||||||
class="spell-list list striped no-border"
|
|
||||||
>
|
|
||||||
<label
|
<label
|
||||||
is="spell-item"
|
is="spell-item"
|
||||||
class="item two-lines item-link"
|
class="item two-lines item-link"
|
||||||
v-for="spell in filteredSpells"
|
v-for="spell in pagedSpells"
|
||||||
:spell="spell"
|
:spell="spell"
|
||||||
>
|
>
|
||||||
</label>
|
</label>
|
||||||
|
<q-pagination
|
||||||
|
class="text-center"
|
||||||
|
v-model="state.page"
|
||||||
|
:max="numPages"
|
||||||
|
></q-pagination>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
|
import { Utils } from 'quasar'
|
||||||
import Query from '../query'
|
import Query from '../query'
|
||||||
import SpellItem from './Spellitem'
|
import SpellItem from './Spellitem'
|
||||||
import { state } from '../store'
|
import { state } from '../store'
|
||||||
|
@ -24,24 +26,43 @@ Vue.component('spell-item', SpellItem)
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
return { state }
|
return {
|
||||||
|
state,
|
||||||
|
perPage: 0
|
||||||
|
}
|
||||||
},
|
},
|
||||||
props: [
|
props: [
|
||||||
'spells'
|
'spells'
|
||||||
],
|
],
|
||||||
|
mounted () {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
window.addEventListener('resize', this.newPerPage)
|
||||||
|
})
|
||||||
|
this.calculateNewPage()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
newPerPage: Utils.debounce(function () {
|
||||||
|
this.calculateNewPage()
|
||||||
|
}, 100),
|
||||||
|
calculateNewPage () {
|
||||||
|
let fontSize = 14
|
||||||
|
this.perPage = Math.floor(window.innerHeight / (fontSize * 5)) - 4
|
||||||
|
}
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
numPages () {
|
||||||
|
return Math.ceil(this.filteredSpells.length / this.perPage)
|
||||||
|
},
|
||||||
filteredSpells () {
|
filteredSpells () {
|
||||||
return new Query(this.spells)
|
return new Query(this.spells)
|
||||||
.search('name', this.state.search)
|
.search('name', this.state.search)
|
||||||
.sort(this.state.sortBy)
|
.sort(this.state.sortBy)
|
||||||
.paginate(1, this.state.loadedPagination * 20)
|
|
||||||
.results
|
.results
|
||||||
}
|
},
|
||||||
},
|
pagedSpells () {
|
||||||
methods: {
|
return new Query(this.filteredSpells)
|
||||||
loadMore (index, done) {
|
.paginate(this.state.page, this.perPage)
|
||||||
this.state.loadedPagination += 1
|
.results
|
||||||
done()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ export default new VueRouter({
|
||||||
routes: [
|
routes: [
|
||||||
{ path: '/', component: load('Index') }, // Default
|
{ path: '/', component: load('Index') }, // Default
|
||||||
{ path: '/my', component: load('Myspells') },
|
{ path: '/my', component: load('Myspells') },
|
||||||
|
{ path: '/spell/:name', component: load('Spell') },
|
||||||
{ path: '*', component: load('Error404') } // Not found
|
{ path: '*', component: load('Error404') } // Not found
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,7 +7,7 @@ export let state = {
|
||||||
search: '',
|
search: '',
|
||||||
sortBy: 'name',
|
sortBy: 'name',
|
||||||
previousSortBy: 'name',
|
previousSortBy: 'name',
|
||||||
loadedPagination: 1
|
page: 1
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dispatch (action) {
|
export function dispatch (action) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue