vue父组件获取子组件的数据

1.写子组件时候在子组件上写上ref属性

<child-first ref="first" ></child-first>

 

2.调用子组件的方法或者data

//调用方法  还能获取返回值 
let childData = this.$refs.first.getData();

//直接获取子组件的值
console.log(this.$refs.first.res)

注意:这个“first”是唯一标识 上下要一致

posted on 2019-12-19 16:21  rainbowLover  阅读(9892)  评论(0编辑  收藏  举报