[英]Use multiple components in react
我是reactjs的新手,正在使用它創建一個項目。 使用多個組件時出現問題。 這是場景
加載頁面時,兩個組件的加載類型均為getcpeyearlysval和getvnfyearlysval類型的值
setDataMeter1(){
//here i want only type cpe componnet will load
}
<Speedometer type = "cpe" getcpeyearlysval={this.objSpeedometer.getcpeyearlys}/>
<Speedometer type = "vnf" getvnfyearlysval={this.objSpeedometer.getvnfyearlys}/>
現在我想當我調用this.setDataMeter1函數時,只有類型為cpe的組件才可以工作,但問題是兩個調用都沒有。
<select value={this.state.selectValue} onChange={this.setDataMeter1}>
In Speedometer component:
renderIcon(key, val) {
if(key == 'vnf') {
console.log("vnf")
}
if(key == 'cpe'){
console.log("cpe")// this condition should met
}
}
render() {
return (
this.renderIcon(this.props.type, this.props)
);
}
}
但是我的問題是車速表的兩個條件都滿足。
renderIcon(props) {
if(props.type == 'vnf') {
return <Text>hey this is vnf </Text>
}
if(props.type == 'cpe'){
return <Text>hey this is cpe </Text>
}
}
render() {
return (
this.renderIcon(this.props)
);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.