Answer the question
In order to leave comments, you need to log in
How to pass from component to parent in Vue?
Hey! In a single-component vue structure, I pass from the child component to the parent via emmit, everything works.
But it's not like that.
Vue.component('line-chart', {
extends: VueChartJs.Line,
data: function () {
return {
message: 'test'
}
},
mounted () {
this.$emit('changeMessage', this.message);
}
})
var vm = new Vue({
el: '.app',
data: {
data: null,
message: 'Hello World'
},
methods: {
changeMessage: function () {
this.message = 'test';
}
}
})
<div class="app">
{{ message }}
<line-chart :chart-data="data" @changeMessage="changeMessage"></line-chart>
</div>
Answer the question
In order to leave comments, you need to log in
@changeMessage="changeMessage"
event listener directivesv-on
inside DOM templates are automatically converted to lowercase (due to HTML's case insensitivity), sov-on:myEvent
will becomev-on:myevent
- making event listenersmyEvent
impossible
in parent write:
var vm = new Vue({
el: '.app',
data: {
data: null,
message: 'Hello World'
},
mounted () {
this.$on('changeMessage', (message) => {
this.message = message
})
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question