zoukankan      html  css  js  c++  java
  • 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) => {
      ......
    }

  • 相关阅读:
    es6
    ES6
    ES6
    css3
    滚动穿透的6种解决方案【已自测】
    css特效
    css布局
    css布局
    js
    【消灭代办】第5周
  • 原文地址:https://www.cnblogs.com/kongwei/p/10412987.html
Copyright © 2011-2022 走看看