LoginSignup
0
0

More than 3 years have passed since last update.

【vue】dispatchに第三引数を渡したい

Posted at

結論

vueのdispatchで第三引数を渡したい時は、第二引数に オブジェクトを用いる。

ショッピングカートに、商品情報とユーザー情報の2つをdispatchの引数として入れる。

失敗例

以下のように第一引数に path, 第二引数に item, 第三引数に userIdを入れたところうまくいかなかった。

this.$store.dispatch('shop/addCart', this.item, this.userId)

成功例

第二引数をオブジェクトにすることで、複数の値を格納することができた。

this.$store.dispatch('shop/addCart', {
  item: this.item, 
  userId: this.userId
})
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0