Skip to content

Instantly share code, notes, and snippets.

@flexbox
Last active January 30, 2020 15:57
Show Gist options
  • Save flexbox/e326bb24da5874f127789a86b6d3fc6a to your computer and use it in GitHub Desktop.
Save flexbox/e326bb24da5874f127789a86b6d3fc6a to your computer and use it in GitHub Desktop.
Async / await cheatsheet
async customerUpdate(fields) {
try {
const { status, data } = await this.$axios…
return { status, data }
} catch (e) {
throw new Error(e)
}
}
async updateUserFields({ commit }, fields) {
commit('SET_LOADING', true)
const { status, data } = await this.$userApi.customerUpdate(fields)
commit('SET_LOADING', false)
commit('SET_USER', status === 200 ? data : null)
return status === 200
},
async save() {
const birthday = …
const res = await this.updateUserFields({ birthday })
if (res) {
this.$emit('success')
this.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment