Proper dispatch events, error handling
This commit is contained in:
parent
85492f8a6e
commit
25e6af91c8
2 changed files with 37 additions and 13 deletions
|
@ -13,9 +13,9 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { Loading } from 'quasar'
|
import { Loading, Dialog } from 'quasar'
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import { state } from '../store'
|
import { state, dispatch } from '../store'
|
||||||
import SpellList from './Spelllist'
|
import SpellList from './Spelllist'
|
||||||
import 'whatwg-fetch'
|
import 'whatwg-fetch'
|
||||||
|
|
||||||
|
@ -30,18 +30,29 @@ export default {
|
||||||
mounted () {
|
mounted () {
|
||||||
if (this.state.spells.loaded === false) {
|
if (this.state.spells.loaded === false) {
|
||||||
Loading.show()
|
Loading.show()
|
||||||
}
|
|
||||||
|
|
||||||
fetch('./statics/dnd5e.json')
|
fetch('./statics/dnd5e.json')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(spells => {
|
.then(spells => {
|
||||||
this.state.spells = {
|
dispatch({
|
||||||
|
type: 'SPELLS_RESOLVED',
|
||||||
|
data: {
|
||||||
loaded: true,
|
loaded: true,
|
||||||
data: spells
|
data: spells
|
||||||
}
|
}
|
||||||
Loading.hide()
|
|
||||||
})
|
})
|
||||||
.catch(reason => console.error('Unable to retrieve spells list:', reason))
|
})
|
||||||
|
.catch(reason => {
|
||||||
|
let message = 'Unable to retrieve spells list'
|
||||||
|
Dialog.create({
|
||||||
|
title: 'Error',
|
||||||
|
message,
|
||||||
|
nobuttons: true
|
||||||
|
})
|
||||||
|
console.error(message, reason)
|
||||||
|
})
|
||||||
|
.then(() => { Loading.hide() })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
13
src/store.js
13
src/store.js
|
@ -4,3 +4,16 @@ export let state = {
|
||||||
data: []
|
data: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function dispatch (action) {
|
||||||
|
switch (action.type) {
|
||||||
|
case 'SPELLS_RESOLVED':
|
||||||
|
state.spells = action.data
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
state,
|
||||||
|
dispatch
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue