I have following scenario:
I have an dropdown component. Whenever you select some propertie it emits the selected value in my case the color with
this.$emit("setColor", "somecolor")
In my parent component i listen to this event with <mycomponent @setColor="setColor" />
and execute an method called setColor
This component is actually rendered in a v-for
and for this i want to pass my index of the current iteration to the setColor
, how do i do that?
i tried with @setColor="setColor(i)"
but then my color that i am passing from the child to the parent is undefined
You can use $event
keyword to pass the event payload. So you can call your method like below :
@setColor="setColor($event,i)"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.