s8e112.5 sibling communication

This commit is contained in:
Tyrel Souza 2018-04-17 21:53:02 -04:00
parent e421d3c06b
commit e43128f316
No known key found for this signature in database
GPG Key ID: 5A9394D4C30AEAC0
3 changed files with 17 additions and 4 deletions

View File

@ -10,10 +10,11 @@
:name="name" :name="name"
@nameWasReset="name = $event" @nameWasReset="name = $event"
:resetFn="resetName" :resetFn="resetName"
:userAge="age"
></app-user-detail> ></app-user-detail>
</div> </div>
<div class="col-xs-12 col-sm-6"> <div class="col-xs-12 col-sm-6">
<app-user-edit></app-user-edit> <app-user-edit :userAge="age" @ageWasEdited="age = $event"></app-user-edit>
</div> </div>
</div> </div>
</div> </div>
@ -27,6 +28,7 @@
data(){ data(){
return { return {
name: "Tyrel", name: "Tyrel",
age: 29
} }
}, },
methods: { methods: {

View File

@ -2,7 +2,7 @@
<div class="component"> <div class="component">
<h3>You may view the User Details here</h3> <h3>You may view the User Details here</h3>
<p>Many Details</p> <p>Many Details</p>
<p>User Name: {{ switchName() }}</p> <p>User Name: {{ switchName() }}, {{userAge}}</p>
<button @click="resetName">Reset Name</button> <button @click="resetName">Reset Name</button>
<button @click="resetFn()">Reset Name Fn</button> <button @click="resetFn()">Reset Name Fn</button>
</div> </div>
@ -10,7 +10,8 @@
<script> <script>
export default { export default {
props: { props:{
userAge: Number,
name: { name: {
type: String, type: String,
}, },

View File

@ -1,11 +1,21 @@
<template> <template>
<div class="component"> <div class="component">
<h3>You may edit the User here</h3> <h3>You may edit the User ({{userAge}}) here</h3>
<p>Edit me!</p> <p>Edit me!</p>
<button @click="editAge">Edit Age</button>
</div> </div>
</template> </template>
<script> <script>
export default {
props: ['userAge'],
methods: {
editAge(){
this.userAge = 30;
this.$emit('ageWasEdited', this.userAge)
}
}
}
</script> </script>
<style scoped> <style scoped>