Vue & React组件间的传递

it2022-05-09  36

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


最新回复(0)