**子传父通过$ref的形式
子传父通过$ref的形式**
<template>
<div>
{{father_pro}}
<Son ref="son"></Son>
</div>
</template>
<script>
import Son from '@/Son'
export default {
data(){
return {
father_pro:'父组件的值'
}
},
methods:{
father_fun(){
console.log('父组件的方法')
this.$refs.son.son_fun() //调用子组件中方法
this.father_pro=this.$refs.son_a //调用子组件中的属性
}
},
components:{
Son
}
}
</script>
子组件
<template>
<div>
<h5>子组件</h5>
</div>
</template>
<script>
export default {
data(){
return {
son_a:'son_a'
}
},
methods:{
son_fun(){
console.log('子组件的方法')
}
}
}
</script>