- Notifications
You must be signed in to change notification settings - Fork49
Closed
Description
| createPost({commit},message){ |
Hi!
I would like to propose async/await approach.
There are some more lines of code and it looks more habitually (to me :) )
async/await version
actions: { async createPost ({commit}, message) { commit('CREATING_POST') try { const response = await PostAPI.create(message) commit('CREATING_POST_SUCCESS', response.data)) return response.data } catch (err) { commit('CREATING_POST_ERROR', err) return null } }, // ...}And some additional actions to make it work (async/await).
webpack.config.js
.configureBabel(function(babelConfig) { babelConfig.plugins.push("@babel/plugin-transform-runtime"); })Babel 7
$ yarn add -D @babel/plugin-transform-runtime$ yarn add -D @babel/runtimepackage.json
{ ... "browserslist": [ "> 0.5%", "last 2 versions", "Firefox ESR", "not dead" ] ...}