场景

. 在使用vue components dispatch Vuex actions的时候需要传递参数给多个参数actions 
  但是在actions 只是可以接收到两个参数的问题

分析

. vuex actions 固定接受的第一个参数是dispatch对象 第二个参数是使用者本身定制的参数

参考

. `https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment`

解决

调用的时候 第二个参数传递成多个元素的对象这样在actions 中第二个参数就可以搞定了
this.$store.dispatch('delTask', {task, index});
actions使用ES2015参数解析

        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);
                }
            });
        }
Logo

前往低代码交流专区

更多推荐