components in the communication vue

Communication components 

  1. Sons communication component 

 Case:

 
// parent-child communication components ideas
1 // data to the parent component subassembly custom data binding on individual subassembly
// 2 sub-assembly accepted custom that used props: No. property

Vue.component('father',{
template:'#father',
data () {// a data component the data must be a function
return {
money:1000
}
}
})

Vue.component ( 'a', {
template:'#son',
props:['hello']
//props:['money']
// props: {// Data Validation
// 'monery':Number
// }
})
 

 Communication sub parent component

// definition component
Vue.component('father',{
template:'#father',
data(){
return {// for receiving data to subassembly
shou: 0
}
},
methods: {// event handler method defined in the parent assembly method then the parent component has the form of custom binding subassembly body son
fn (da) {// Parameters receiving subassembly
this.shou=da
}
}
})

Vue.component ( 'a', {
template:'#son',
data () {// first subassembly data
return {
money:5000
}
},
methods:{
givehongbao () {
this.$emit('give',this.money)
//. $ Emit two transmission parameters Parameter 1 Parameter 2 give the name of the method subassembly custom data pass through this money
}
}

})

Guess you like

Origin www.cnblogs.com/wanghsing/p/11415393.html