我使用的是vue.js和Laravel 5.6.12
下面是我遵循的一步一步的指导方针。
npm install vue-google-autocomplete --save
然后在app.js中添加了以下代码
import VueGoogleAutocomplete from 'vue-google-autocomplete'
Vue.component('vue-google-autocomplete', VueGoogleAutocomplete);
最后,下面是模板中的代码。
<vue-google-autocomplete
id="map"
classname="form-control"
placeholder="Start typing">
</vue-google-autocomplete>
我得到了下面的错误
挂载钩子中出现
错误:"ReferenceError: google is not defined“
我在上面的代码中遗漏了什么吗?
发布于 2018-06-02 00:56:53
似乎你还没有将谷歌地图脚本添加到你的index.html
中。
这个组件(Vue Google Autocomplete)使用Google Maps Places API来获取自动完成的地理建议,所以你必须在你的
中包含Google Maps Places API:
<!DOCTYPE html>
<html>
<head>
…
<!-- NEXT LINE IS SUPER IMPORTANT -->
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_HERE&libraries=places"></script>
</head>
<body>
…
</body>
</html>
如果你使用的是vue cli,你可以把它添加到这个文件中:https://github.com/vuejs-templates/webpack/blob/develop/template/index.html
要获取密钥,请执行以下步骤
API Console.
,请参阅使用限制
获取接口密钥here更多信息
https://stackoverflow.com/questions/50647627
复制相似问题