After reading an answer on Stack Overflow, I was able to successfully pass a value from a child component to the parent and call a method in the parent using that value. However, my challenge is that the child components are generated dynamically with the use of v-for
, and I also need to pass the index of each component to the method along with the value.
This is what I am aiming for:
<component v-for="(component, index) in components" :key="index"
:is="component" :index="index" @title-change="setTitle(value, index)" />
If I simply use
@title-change="setTitle"
, the value gets passed correctly to the setTitle
method without needing to explicitly provide it as a parameter.
However, I also want to include the index
in the method call. Unfortunately, none of the following attempts seem to work:
@title-change="setTitle(value, index)"
@title-change="setTitle(index, value)"
@title-change="setTitle(index)"
It's worth mentioning that I am working with Vue 2.