所有的事件本质上是回调,是钩子,也就是有一个事情,有可能会发生,发生了你再来找我,什么时候发生了不知道,但是发生了我给你一个入口
父组件向子组件传递的时候 ,子组件通过prop来接这个组件的参数
有点类似于react的组件参数传递
Vue.component(‘child’, {
template: <div> <h4>来自父亲的Value{{myValue}}</h4> <input type="text" v-model="myValue.d"> </div>
,
props: [‘myValue’],
methods: {
},
update: function () {
console.log('子组件的update', this.myValue.d)
},
mounted: function () {
console.log('子组件的mount', this.myValue.d)
}
})
// 父组件
Vue.component('parent', {
template: `
<div>
<h4>父亲的Value{{parentValue2}}</h4>
<input type="text" v-model="parentValue2.d">
<hr/>
<child :myValue = "parentValue2"></child>
</div>
`,
data: function () {
return {
parentValue: '乌拉乌拉',
parentValue2: {
d: 'wula'
}
}
},
update: function () {
console.log('父组件的update', this.parentValue2.d)
}
})
new Vue({
el: '#app'
});