vuex actions传递多参数的处理

场景
. 在使用vue components dispatch Vuex actions的时候需要传递参数给多个参数actions
  但是在actions 只是可以接收到两个参数的问题
12
 
分析
. vuex actions 固定接受的第一个参数是dispatch对象 第二个参数是使用者本身定制的参数
1
 
参考
. `https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment`
1
解决

  调用的时候 第二个参数传递成多个元素的对象这样在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);
                }
            });
        }
————————————————
版权声明:本文为CSDN博主「cominglately」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/cominglately/article/details/80515419

猜你喜欢

转载自www.cnblogs.com/sexintercourse/p/12197357.html