Created
January 9, 2019 12:08
-
-
Save sajt/d7e62a2578cbea555354affe8683bcad to your computer and use it in GitHub Desktop.
Global error handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<q-layout view="lHh Lpr lFf"> | |
<q-layout-header> | |
<q-toolbar | |
color="primary" | |
:glossy="$q.theme === 'mat'" | |
:inverted="$q.theme === 'ios'" | |
> | |
<q-btn | |
flat | |
dense | |
round | |
@click="leftDrawerOpen = !leftDrawerOpen" | |
aria-label="Menu" | |
> | |
<q-icon name="menu" /> | |
</q-btn> | |
<q-toolbar-title> | |
Antares-Kód | |
</q-toolbar-title> | |
</q-toolbar> | |
</q-layout-header> | |
<q-page-container> | |
<router-view /> | |
</q-page-container> | |
</q-layout> | |
</template> | |
<script> | |
import { mapGetters } from 'vuex' | |
export default { | |
name: 'MyLayout', | |
data () { | |
return { | |
leftDrawerOpen: this.$q.platform.is.desktop | |
} | |
}, | |
computed: { | |
...mapGetters({ | |
loading: 'application/loading', | |
errorMessage: 'application/errorMessage' | |
}) | |
}, | |
watch: { | |
loading (val, oldVal) { | |
if (val) { | |
this.$q.loading.show() | |
} else { | |
this.$q.loading.hide() | |
} | |
}, | |
errorMessage (val, oldVal) { | |
this.$q.notify(val) | |
} | |
} | |
} | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<q-page padding> | |
<q-field label="Save"> | |
<q-btn round color="secondary" icon="card_giftcard" @click="pushSubmit" /> | |
</q-field> | |
</q-page> | |
</template> | |
<script> | |
export default { | |
methods: { | |
pushSubmit () { | |
this.$store.dispatch('application/setLoading', {value: true}) | |
this.$store.dispatch('application/setErrorMessage', {message: 'Hajrá'}) | |
setTimeout(() => { | |
this.$store.dispatch('application/setLoading', {value: false}) | |
}, 3000) | |
} | |
} | |
} | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function setLoading (context, payload) { | |
context.commit('SET_LOADING', payload.value) | |
} | |
export function setErrorMessage (context, payload) { | |
context.commit('SET_ERROR_MESSAGE', payload.message) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function loading (state) { | |
return state.loading | |
} | |
export function errorMessage (state) { | |
return state.errorMessage | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// It is only the default | |
import state from './state' | |
import * as getters from './getters' | |
import * as mutations from './mutations' | |
import * as actions from './actions' | |
export default { | |
namespaced: true, | |
state, | |
getters, | |
mutations, | |
actions | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function SET_LOADING (state, value = true) { | |
state.loading = value | |
} | |
export function SET_ERROR_MESSAGE (state, value = '') { | |
state.errorMessage = value | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
loading: false, | |
errorMessage: '' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment