- Fixed methods of spell list
This commit is contained in:
@@ -8,5 +8,8 @@ export default {
|
||||
},
|
||||
getOne(id) {
|
||||
return api.get(`${resource}/${id}`)
|
||||
},
|
||||
getSpellsFromOne(id) {
|
||||
return api.get(`${resource}/${id}/spells`)
|
||||
}
|
||||
}
|
||||
@@ -79,6 +79,7 @@ import AddSpellCard from "./add-spell-card"
|
||||
// API
|
||||
import { RepositoryFactory } from "~/api/repositories"
|
||||
const Spells = RepositoryFactory.get('spells')
|
||||
const Schools = RepositoryFactory.get('schools')
|
||||
|
||||
export default {
|
||||
name: 'spellslist',
|
||||
@@ -107,10 +108,16 @@ export default {
|
||||
},
|
||||
beforeMount() {
|
||||
this.spells = this.computedSpells
|
||||
if (!this.school_id) {
|
||||
this.getInitialSpells()
|
||||
} else {
|
||||
this.getInitialSchoolSpells()
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (!this.school_id) {
|
||||
this.scroll()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getInitialSpells() {
|
||||
@@ -129,6 +136,22 @@ export default {
|
||||
console.log(err)
|
||||
})
|
||||
},
|
||||
getInitialSchoolSpells() {
|
||||
Schools.getSpellsFromOne(this.school_id)
|
||||
.then(v => {
|
||||
this.loading = true
|
||||
let spells = this.computedSpells
|
||||
spells.push(v.data.spells)
|
||||
this.spells = spells[0]
|
||||
})
|
||||
.then(() => {
|
||||
this.currentIndex++
|
||||
this.loading = false
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
},
|
||||
scroll() {
|
||||
window.onscroll = () => {
|
||||
if (((window.innerHeight + window.scrollY) - document.body.offsetHeight) >= -1) {
|
||||
|
||||
Reference in New Issue
Block a user