我正在使用google地图显示位置。但是我在componentdidmount阶段更新了地图地址。而且我正在使用另一个函数来创建dom元素。因此,当我第一次进入maps页面时,会出现错误。因为渲染后将要插入地图的dom元素将位于DOM内。 因此,如果没有刷新,我将无法对地图页面做出反应。刷新之后我可以。有什么想法吗? (我正在使用MERN)
componentDidMount() {
const {
match: {
params: { id }
}
} = this.props;
this.props.getListById(id)
.then(list => {
return getLocationAddressAndPlace(
document.getElementById('__maps'), // This _maps div is not created, will be created after the render.
list.address.locationName
)
})
.catch(err => {
toast.error(err);
});
}