場景
在使用vue components dispatch Vuex actions的時候需要傳遞參數(shù)給多個參數(shù)actions
但是在actions 只是可以接收到兩個參數(shù)的問題
分析
vuex actions 固定接受的第一個參數(shù)是dispatch對象 第二個參數(shù)是使用者本身定制的參數(shù)
參考
`https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment`
解決
調(diào)用的時候 第二個參數(shù)傳遞成多個元素的對象這樣在actions 中第二個參數(shù)就可以搞定了
this.$store.dispatch('delTask', {task, index}); actions使用ES2015參數(shù)解析
delTask : function (store, {index, task}) { let url = 'http://zhihu.carsonlius_liu.cn/api/tasks/' + task.id; Http.$http.delete(url).then(function (response) { if (response.body.status === 'success') { store.commit('delSpecialTask', index); } }); }以上這篇vuex actions傳遞多參數(shù)的處理方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答