我刚刚将我的 React 应用程序从 15.x 升级到 React 16.0,现在出现以下错误。代码本身并没有改变,只是它现在是一个 React 16.0 应用程序。
'google' 未定义 no-undef
我在创建的 util 方法中使用自动完成功能,如下所示:
const map = new google.maps.Map(document.createElement('div'));
const googlePlacesAutocomplete = new google.maps.places.AutocompleteService();
const googlePlacesService = new google.maps.places.PlacesService(map);
export const googlePlacesAutoComplete = (keyword, callback) => {
googlePlacesAutocomplete.getQueryPredictions({input: keyword}, (predictions, status) => {
if(status !== google.maps.places.PlacesServiceStatus.OK) return callback(null);
return callback(predictions);
});
}
我只是从静态 HTML 页面指向 Google Places 库作为我的 React 应用程序的入口点。
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places&key=my-api-key"></script>
知道有什么问题吗?有什么建议可以解决这个问题吗?