首页 > 语言 > JavaScript > 正文

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

2024-05-06 15:29:50
字体:
来源:转载
供稿:网友

场景

在使用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);    }   });  }

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选