Answer the question
In order to leave comments, you need to log in
How to pass data on an event in Vuejs?
How to pass data on an event in Vuejs? For example, we have 10 multi-colored blocks. How, when clicking on one of the bottoms, to pass the color of this block to the "backgrond-color" of the "body" tag?
Answer the question
In order to leave comments, you need to log in
You subscribe the child component to a click, after which you write something like this in the methods: this.$emit('meClicked', this.bgc), that is, you generate an event and data, for example, you pass the background color as payload, as an event object.
The parent subscribes to the event that the @meClicked child component generates, a handler function is created in the methods that will receive the event data and do something with them, for example, change the background for body.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question