vuejs / Discussion

Vue.js discussion
167 stars 17 forks source link

Hi Guys, i'm tring to pass data from an component to another, but i cant reflact the parent data in to the child, anyone can help me please. #483

Open patrickcr opened 8 years ago

patrickcr commented 8 years ago

this is my parent component

<template>
  <div>
       <h1>Hello, World</h1>
      <input v-model="user.name">
     <label>Name</label>      
  </div>
    <usercontrol></usercontrol>
</template>
import` UserControl from '../components/UserControl.vue'
    export default {
             components: {
            'usercontrol': UserControl,
            props: ['tab'] 
          },
        data: function() {
            return { 
                user: null,
                tab: 'Shared message'

            }
        },
        created: function () {
            this.$on('child-created', function (child) {
               this.user = child.user;
            })
        }
    };

this is my child component

<template> 
    <div>
        <h1>Authentication Control</h1>
        <input type='text' v-model="user.name"></input>
         <label>parent</label>
       <pre>{{tab }}</pre>
    </div>
</template>
<script>
    export default {
        data: function() {
            return {    `
                user: { name:'Luis' }
            }
        },
        created: function () {
                this.$dispatch('child-created', this)
        },

</script>`<template>
  <div>
       <h1>Hello, World</h1>
      <input v-model="user.name">
     <label>Name</label>      
  </div>
    <usercontrol></usercontrol>
</template>

import` UserControl from '../components/UserControl.vue'
    export default {
             components: {
            'usercontrol': UserControl,
            props: ['tab'] 
          },
        data: function() {
            return { 
                user: null,
                tab: 'Shared message'

            }
        },
        created: function () {
            this.$on('child-created', function (child) {
               this.user = child.user;
            })
        }
    };

i create an Property for Tag in parent, but i can't see the value in the child component, i ne```ed also to know how pass the child data to the parent, i'musin and exmaple from vue, on dispash event to detect when child is cretaed and then i pass the value from child to parent.. Is it no to mush complicated???