react问题:xxx is not undefind

167 阅读1分钟

一般这种是两种情况,直接写解决,后面在更新问题截图和分析

react绑定的方法this为空,解决

案例:changeDCtrollParam is not undefind

初步分析:this的导向问题,在constructor时候,绑定this

constructor(props) {        
    super(props);       
     this.changeDCtrollParam = this.changeDCtrollParam.bind(this);
 };

.xxxx   is not undefind

案例:antd

this.fromRef.current.setFieldsValue(intval)

报错:setFieldsValue is not undefind

初步分析:调用此方法时from的DOM还没初始化,使用try{} catch(){}

try {        
    this.fromRef.current.setFieldsValue(fromData);  
  } catch (error) { }