Skip to content

Instantly share code, notes, and snippets.

@timwis
Last active February 26, 2018 00:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save timwis/6eb9aa0fc8eed1d36b6dcc7e7db84452 to your computer and use it in GitHub Desktop.
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