- 新增和编辑时同一个组件;
- modal子组件根据父组件传进去的{type:'edit',visible:'',code:''},来获取基础数据;
modal子组件:
componentDidMount() {
console.log('this.props',this.props)
if (this.props.data.type === "add"){
//this.getAddData()
}else{
//this.getEditData(this.props.data.code)
}
//这是一个新增,编辑的modal组件;
//希望在父组件点击时,打开这个modal,根据传进来的 data:{type:'',visible:'',code:''},处理业务逻辑
//这是子组件的componentDidMount,this.props.data的值取不到,在哪里获取?
//如果这个业务逻辑不应该写在这里,那么怎么写?
}
自力更生吧。
getDerivedStateFromProps 和 componentWillReceiveProps 生命周期都可以获取。目前正在研究他们的区别,用哪个更合适。