首页 > 解决方案 > 在 vue.js 中实现谷歌自动完成的问题

问题描述

我正在尝试在带有 laravel 的 vue.js 中使用谷歌自动完成,但它给了我错误:

[Vue warn]: Error in mounted hook: "ReferenceError: google is not defined" 
found in
---> <VueGoogleAutocomplete> at /src/components/VueGoogleAutocomplete.vue
       <App> at /src/App.vue

         <Root>

这是我要实现的代码的链接:

https://codesandbox.io/s/nifty-bardeen-5eock

标签: javascriptjqueryvue.jslaravel-5vuejs2

解决方案


检查您的代码框后,我注意到您没有在 public/index.html 的 head 标记中包含 Google Maps Places API。

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_HERE&libraries=places"></script>

推荐阅读