vuex actions传递多参数的处理方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

vuex actions传递多参数的处理方法

cominglately   2020-05-16 我要评论

场景

在使用vue components dispatch Vuex actions的时候需要传递参数给多个参数actions

但是在actions 只是可以接收到两个参数的问题

分析

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

参考

`https:/https://img.qb5200.com/download-x/developer.mozilla.org/zh-CNhttps://img.qb5200.com/download-x/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);
    }
   });
  }

以上这篇vuex actions传递多参数的处理方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们