Vuex 中 使用 Action 處理異步請求時,常規寫法以下:html
getMenuAction:(context) =>{ context.commit('SET_MENU_LIST',['承保2','覈保2']) } }
咱們也可使用以下簡化寫法,以下:異步
actions:{ getMenuAction:({commit}) =>{ commit('SET_MENU_LIST',['承保2','覈保2']) } }
這是一種怎麼的寫法呢?spa
其實這是 ES6 中一種被稱爲 變量解構賦值 新的語法知識,可參考個人另一篇文章 變量解構賦值。code
咱們能夠看看 Vuex 中 註冊 Action的源碼以下:
htm
常規寫法中的 context = { dispatch: local.dispatch,
commit: local.commit,
getters: local.getters,
state: local.state,
rootGetters: store.getters,
rootState: store.state }blog
使用 變量解構賦值後 { commit } 的 commit= context.commit 了。get