Last active
February 26, 2018 00:15
-
-
Save timwis/6eb9aa0fc8eed1d36b6dcc7e7db84452 to your computer and use it in GitHub Desktop.
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
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 | |
}) | |
} | |
} | |
} |
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
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