【发布时间】:2018-03-15 02:40:44
【问题描述】:
我正在尝试将 Google Maps API 从 Google Maps API 提取到我的 Vue.js 应用程序中。我已检索到生成的 API 密钥,并且正在尝试显示地图。当我运行该应用程序时,Atom 抛出一个未找到模块的错误消息,并且浏览器显示:Can't resolve 'https://maps.googleapis.com/maps/api/js?key=MYAPIKEY&callback=initMap' in 'C:\Atom Projects\Project\client\src\components' 知道我做错了什么吗?
MyComponent.vue
<template>
<div>
<div id="map">
</div>
</div>
</template>
<script>
function initMap () {
var options = {
zoom: 8,
center:{lat:39.9612,lng:-82.9988}
}
var map = new google.maps.Map(document.getElementById('map'), options);
}
</script>
<script async defer type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=MYAPIKEY&callback=initMap">
</script>
<style>
#map{
height: 400px;
width: 100%;
}
</style>
浏览器完全错误
./src/components/MyComponent.vue
Module not found: Error: Can't resolve 'https://maps.googleapis.com/maps/api/js?key=MYAPIKEY&callback=initMap' in 'C:\Atom Projects\MyProject\client\src\components'
@ ./src/components/MyComponent.vue 8:0-131 9:0-144
@ ./src/router/index.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8081 webpack/hot/dev-server ./src/main.js
【问题讨论】:
标签: javascript google-maps google-maps-api-3 vue.js vuejs2