Vue & React组件间的传递

Vue: ref 传值

父组件<test1 ref="AAA"></test1>
子组件<img ref="BBB" /> methods:{ afun(){ ... } }

if (this.$refs.AAA) {
  this.$refs.AAA.$refs.BBB.src = "xxx";
  this.$refs.AAA.afun()
}

#############################################################################

React: 父组件调用子组件的方法,或更新子组件state

父组件:
<test1 onRef="this.CCC"></test1>
CCC = (ref) => {
  this.DDD = ref;
}

this.DDD.setState(...)或者
this.DDD.bfun(...)  

子组件:
componentDidMount(){
  this.props.onRef(this);
}

bfun= (ref) => {
  ......
}

原文地址:https://www.cnblogs.com/kongwei/p/10412987.html