我在 this.setState 中遇到错误。我必须绑定函数吗?还是有语法问题?能 有人请帮忙吗?
componentDidMount() {
let mobile = false;
this.setState({
displayZipSearchPage : true,
geolocation: {
latitude: null,
longitude: null,
shared: false,
supported: false,
},
});
if (isNotEmptyObject(window) && 'navigator' in window) {
if ('geolocation' in window.navigator) {
navigator.geolocation.getCurrentPosition(
(pos) => {
this.setState({ 'The error occurs here'
geolocation: {
latitude: pos.coords.latitude.toString(),
longitude: pos.coords.longitude.toString(),
shared: false,
supported: true,
},
});
},
console.error,
this.geoOptions,
);
}
}
}