Answer the question
In order to leave comments, you need to log in
Why pass an event to a Vue component?
Here is the source https://jsfiddle.net/tagdjyrL/
The following point is not clear to me:
<modal-notifications :aa="isActive" :message="message" @my-event="myEvent"></modal-notifications>
:aa="isActive"
- everything is clear here, we pass props to the component, which will then determine whether the modal window is open in the component or not. @my-event="myEvent"
? this.$emit('my-event', this.isActive)
which the parent listens. And the emit above does not seem to be needed, but without it it does not work. myEvent: function(isActive) {
this.isActive = isActive
}
Answer the question
In order to leave comments, you need to log in
why pass: @my-event="myEvent"
?
aa
:<modal-notifications :aa.sync="isActive" :message="message"></modal-notifications>
closeModalWindow() {
this.$emit('update:aa', false);
},
v-model
. Надо будет заменить имя параметра с aa
на value
(ну или настроить model):props: ['aa', 'message'],
---> props: [ 'value', 'message' ],
:class="{'is-active': aa}"
---> :class="{ 'is-active': value }"
closeModalWindow() {
this.$emit('input', false);
},
<modal-notifications v-model="isActive" :message="message"></modal-notifications>
I do from the descendant this.$emit('my-event', this.isActive)
which the parent listens.
@my-event="myEvent"
.the emit above doesn't seem to be needed, but it doesn't work without it
And another question. What is he doing:
myEvent: function(isActive) { this.isActive = isActive }
Why should it accept anything? You can just take the value from data.
this.isActive
. which you need to update. Update with the value that the dialog box sends. The value that is passed to (i.e., received by) the event handler.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question