VueJS $store.dispatch 发送多个参数 [英] VueJS $store.dispatch send multiple parameters

查看:250
本文介绍了VueJS $store.dispatch 发送多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将第二个参数传递给调度调用:

I want to pass a second parameter to a dispatch call:

 this.$store.dispatch(
          'testAction',
          this.employee.employeeId,
          departmentId
          ));

我的商店操作如下:

async testAction({ dispatch, commit },  employeeId, departmentId) {
    console.log(departmentId);

    return 'Employee Tested';
  },

当我看到 departmentId 的控制台日志时,我得到未定义".

When I see console log for departmentId i get "undefined".

关于如何传递多个参数的任何线索?

Any clue on how to pass multiple parameters?

谢谢

推荐答案

看一下文档:https://vuex.vuejs.org/guide/actions.html#dispatching-actions

基本上,您不能发送多个参数.您需要使用包含参数的 payload 对象进行调度.

Basically, you can't send multiple parameters. You need to dispatch with a payload object containing your parameters.

这篇关于VueJS $store.dispatch 发送多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆