s8e113 EVENT BUSSSSS ALL ABOARD
This commit is contained in:
parent
e43128f316
commit
7b299290de
|
@ -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">
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user