子组件
<script>
export default {
name: 'componentA',
data () {
return {
msg: 'msg from componentA',
message:'',
}
},
props:['msgfromfather'],
methods:{
clickme:function(){
// console.log(this.msgfromfather),
this.$emit("child-tell-me-something",this.msg);
}
}
}
</script>
父组件
<template>
<div id="app">
<p>{{msg}}</p>
<component-a msgfromfather='you die'
v-on:child-tell-me-something='listenToMyBoy' ></component-a>
<p>child say :{{childWords}}</p>
</div>
</template>
<script>
import componentA from "./components/componentA"
export default{
data:function(){
return {
msg:'father',
childWords:'',
}
},
components:{componentA},
methods:{
listenToMyBoy:function(hehe){
console.log(hehe+'')
this.childWords = hehe
}
}
}
</script>
网友评论