s8e113 EVENT BUSSSSS ALL ABOARD

This commit is contained in:
Tyrel Souza 2018-04-17 22:00:48 -04:00
parent e43128f316
commit 7b299290de
No known key found for this signature in database
GPG Key ID: 5A9394D4C30AEAC0
4 changed files with 13 additions and 1 deletions

View File

@ -2,6 +2,7 @@
<div class="component">
<h1>The User Component</h1>
<p>I'm an awesome User!</p>
<p>I'm an awesome {{age}}!</p>
<button @click="changeName">Change My Name from {{name}}</button>
<hr>
<div class="row">

View File

@ -9,6 +9,8 @@
</template>
<script>
import { eventBus } from "../main"
export default {
props:{
userAge: Number,
@ -27,6 +29,11 @@
this.name = 'Tyrel';
this.$emit('nameWasReset', this.name)
}
},
created(){
eventBus.$on('ageWasEdited', (age) => {
this.userAge = age;
})
}
}
</script>

View File

@ -7,12 +7,13 @@
</template>
<script>
import {eventBus } from "../main"
export default {
props: ['userAge'],
methods: {
editAge(){
this.userAge = 30;
this.$emit('ageWasEdited', this.userAge)
eventBus.$emit('ageWasEdited', this.userAge)
}
}
}

View File

@ -1,7 +1,10 @@
import Vue from 'vue'
import App from './App.vue'
export const eventBus = new Vue();
new Vue({
el: '#app',
render: h => h(App)
})