Closed
Description
组件中条件判断两个子组件:
{ENV_TYPE === 'weapp' &&
<CMap
ref={e => this.mapContainer = e}
onFillStart={this.fillStart}
onLoadVehicles={this.loadVehicles}
step={this.props.step}
start={start}
terminate={terminate}
markers={this.state.markers}
order={updatedOrder}
previewOrderConfig={previewOrderConfig}
screenHeight={this.state.screenHeight}
/>
}
{ENV_TYPE === 'h5' &&
<H5Map
ref={e => this.mapContainer = e}
screenHeight={this.state.screenHeight}
step={this.props.step}
onFillStart={this.fillStart}
/>
}
在方法中调用:
/**
- 用户点击定位
**/
setMapCenterByUser = () => {
console.log( this.mapContainer) // null
this.mapContainer && this.mapContainer.setMapCenterByUserLocation(true)
}
如果在组件中不是条件判断显示子组件,该方法中能获取到this.mapContainer实例