<template>
<div>我是首頁組件
<br >
<Header :title="title" :msg="msg" :run="run" :home='this'></Header>
</div>
</template>
<script>
import Header from './Header'
export default {
name:'Homea',
data(){
return {
msg:'我是一個(gè)首頁消息',
title:"首頁"
}
},
components:{
Header
},
methods: {
run(data){
alert('我是父組件的run方法'+data)
}
},
}
</script>
<style scoped>
</style>
子組件
<template>
<div>我是頭部組件--{{title}}---{{msg}}
<br>
<button @click="run('123')">調(diào)用父組件方法</button>
<br>
<button @click="getThis()">獲取父組件里面的數(shù)據(jù)</button>
</div>
</template>
<script>
export default {
name:'Homea',
data(){
return {
}
},
props:['title','msg','run','home'],
methods: {
getThis(){
alert(this.home.msg)
}
},
}
</script>
<style scoped>
</style>