Skip to content

Instantly share code, notes, and snippets.

@timwis timwis/vue-error-1.js
Last active Feb 26, 2018

Embed
What would you like to do?
import { mapActions, mapState } from 'vuex'
export default {
computed: mapState({
services: (state) => state.services
}),
methods: mapActions([
'getServices'
]),
async created () {
try {
await this.getServices()
} catch (err) {
this.$snackbar.open({
message: 'Something went wrong getting your list of services',
type: 'is-danger',
position: 'is-top',
actionText: 'Retry',
onAction: this.getServices // if this fails, no error is shown
})
}
}
}
import { mapState } from 'vuex'
export default {
computed: mapState({
services: (state) => state.services
}),
methods: {
async dispatch (action, errorMessage) {
try {
await this.$store.dispatch(action)
} catch (err) {
this.$snackbar.open({
message: errorMessage,
type: 'is-danger',
position: 'is-top',
actionText: 'Retry',
onAction: this.dispatch.bind(this, action, errorMessage)
})
}
}
},
created () {
this.dispatch('getServices', 'Something went wrong getting your list of services')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.