great article, but i think actions who does async tasks would return a promise.
GET_DATA({commit}){ return A.get(API_URL_ENDPOINT).then((res) =>{ commit('SET_DATA' , res.data); setTimeout(() =>{ commit('IS_LOADING' , false); } , 1000) }).catch((err) =>{ console.error(err) }); }
anyway, i think IS_LOADING would be set to false, even if the http request throws a error.
IS_LOADING
false
async GET_DATA({commit}){ try { const { data } = await A.get(API_URL_ENDPOINT) commit('SET_DATA' , res.data) } catch () { console.error(err) } finally () { setTimeout(() =>commit('IS_LOADING' , false), 1000) } }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
great article, but i think actions who does async tasks would return a promise.
anyway, i think
IS_LOADING
would be set tofalse
, even if the http request throws a error.