Moved pagination functionality to query.js
This commit is contained in:
parent
b7ba325a60
commit
513af3a56b
2 changed files with 9 additions and 4 deletions
|
@ -50,7 +50,7 @@
|
|||
|
||||
<script>
|
||||
import Vue from 'vue'
|
||||
// import Query from '../query'
|
||||
import Query from '../query'
|
||||
import SpellItem from './Spellitem'
|
||||
|
||||
Vue.component('spell-item', SpellItem)
|
||||
|
@ -62,9 +62,8 @@ export default {
|
|||
return trueMax < 1 ? 1 : trueMax
|
||||
},
|
||||
pagedSpells () {
|
||||
let min = this.page * this.perPage - this.perPage
|
||||
let max = min + this.perPage
|
||||
return this.sortedSpells.slice(min, max)
|
||||
return new Query(this.sortedSpells)
|
||||
.paginate(this.page, this.perPage)
|
||||
},
|
||||
sortedSpells () {
|
||||
return this.spells
|
||||
|
|
|
@ -30,4 +30,10 @@ export default class Query {
|
|||
})
|
||||
return this
|
||||
}
|
||||
|
||||
paginate (page = 1, perPage = 10) {
|
||||
let min = page * perPage - perPage
|
||||
let max = min + perPage
|
||||
return this.data.slice(min, max)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue