【发布时间】:2018-01-13 10:59:10
【问题描述】:
除非我按 ctrl+f5,否则 Google 地图不会加载属性。 我在 vue js 挂载的钩子中初始化地图。 显示的错误是
挂载钩子错误:“ReferenceError: google is not defined”
当我按 ctrl+f5 时一切正常
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=****"
async defer></script>
new Vue({
el:'#app',
mounted() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
}
});
【问题讨论】:
-
请提供您的组件代码。
-
代码示例更新
-
TL;DR:您正在使用异步加载,这就是 GMaps 在安装钩子上不可用的原因。它仍在加载中。
-
但在按 ctrl+f5 刷新页面时工作
标签: javascript google-maps google-maps-api-3 vue.js