场景
在使用vue components dispatch Vuex actions的时候需要传递参数给多个参数actions
但是在actions 只是可以接收到两个参数的问题
分析
vuex actions 固定接受的第一个参数是dispatch对象 第二个参数是使用者本身定制的参数
参考
`https://developer.mozilla.org/zh-CN/docs/Web/ /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传递多参数的处理方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
继续阅读与本文标签相同的文章
-
与你同行,才能无障碍
2026-05-18栏目: 教程
-
分布式Id - redis方式
2026-05-18栏目: 教程
-
HTML5 容器入门解析:支付宝 Hybrid 方案原理与实战
2026-05-18栏目: 教程
-
阿里云910会员节:开启时光机领会员大礼包,云产品满减优惠活动
2026-05-18栏目: 教程
-
基于宜搭的“报表分析”实践案例
2026-05-18栏目: 教程
