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

View File

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

View File

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

View File

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