Created
December 2, 2017 03:36
-
-
Save allysonsilva/4a7cbf08be8a327b391ead5a09c1286a to your computer and use it in GitHub Desktop.
Vue.js ⚡️ Eventos - Comunicação entre Pai e Filho
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vue.component('food', { | |
template: '#food', | |
props: ['name'], | |
methods: { | |
vote: function() { | |
this.$emit('voted') | |
} | |
}, | |
}); | |
new Vue({ | |
el: "#app", | |
data: { | |
votes: 0 | |
}, | |
methods: { | |
countVote: function() { | |
this.votes++ | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template id="food"> | |
<button @click="vote">{{ name }}</button> | |
</template> | |
<div id="app"> | |
<div> | |
<h1> {{ votes }} </h1> | |
<food @voted="countVote" name="Cheeseburger"></food> | |
<!-- | |
@voted="countVote" significa que quando o componente filho emitir o evento voted, | |
o método countVote será executado. | |
--> | |
</div> | |
<pre> | |
{{$data}} | |
</pre> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment