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

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

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

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

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

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

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

原文地址:https://www.cnblogs.com/rainbowLover/p/12068508.html