我刚刚将我的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>知道出什么问题了吗?有什么建议可以解决这个问题吗?
发布于 2018-05-30 08:52:55
你试过‘window.google’吗?‘google’是全局的,建议不要使用全局变量。
此外,如果可以的话,尝试将‘google’添加为一个模块,以确保在使用前将其作为veen加载。并可能避免全局变量或任何可能覆盖其值的内容。
https://stackoverflow.com/questions/50577388
复制相似问题