- [API] Segregated API files, Implemented spells-list, component that calls the API

This commit is contained in:
Alexis
2020-04-06 16:39:55 +02:00
parent 37f4913d3e
commit 042c205ce4
11 changed files with 169 additions and 29 deletions

View File

@@ -63,11 +63,11 @@ export default {
name: 'spell-card',
props: {
name: String,
description: Array,
level: String,
description: String,
level: Number,
schools: Array,
ingredients: String,
charge: String,
ingredients: Array,
charge: Number,
cost: String,
variables: Array,
},

View File

@@ -0,0 +1,47 @@
<template>
<div class="spells-list">
<spell-card v-for="(spell, index) in spells" :key="index" v-bind="spell"/>
</div>
</template>
<script>
// Components
import spellcard from "./spell-card"
// API
import { RepositoryFactory } from "../../../api/repositories"
const spellsRepository = RepositoryFactory.get('spells')
export default {
name: 'spellslist',
components: {
'spell-card': spellcard,
},
data() {
return {
loading: false,
spells: []
}
},
created() {
this.computeSpells()
},
methods: {
async fetchSpells() {
const { data } = await spellsRepository.getSpells()
return data
},
async computeSpells() {
this.loading = true
const displaySpells = await this.fetchSpells();
this.loading = false
this.spells = displaySpells.splice(0,10)
}
}
}
</script>
<style>
</style>