Vue pass 2 arguments @click

I’m wondering if it’s possible to pass two (or more) arguments to a method? like this:

<div v-for="(item, index) in arrays" >
<div @click="newData(index, item.Volume)">

methods:{

newData: function(arrIndex, arg2) {
        const dat = this.arrays[arrIndex].arg2;
        this.dat = dat;  
},

I’m trying to pass Volume array as arg2/second argument.

arrays: [
        {name: 'Beth', Volume: [30, 29, 28, 27, 26]},
        {name: 'Tamara', Volume: [30, 29, 28, 27, 26]},
]

This seems a somewhat confusing approach.

In your use-case you’re passing the index as an argument to then re-access the same array within your method.

Since you already have access to the Volume property within your v-for, you should be able to just pass it as the first argument:

<div @click="newData(item.Volume)">

newData(volume) {
  this.dat = volume
},

As an aside, your Volume object property should be lowercase if possible, e.g. volume.

2 Likes

This is great! Thanks so much for your help!