It's a little fussy for this to work without using a library, and there may be cleaner ways, but you can just import the library and use it in your components if you want to get started.
First, do not use the defer and async parameters in the <script> . Download it in index.html :
<script src="https://maps.googleapis.com/maps/api/js?key=yourKey"></script>
Then in your component you can access the global google and pass the element to it after installing the component. For example, using the setting from Vuejs cli:
<template> <div class="hello"> <h1>{{ msg }}</h1> <div id="myMap"></div> </div> </template> <script> export default { name: 'hello', data () { return { msg: 'Welcome to Your Vue.js App' }}, mounted: function() { console.log("map: ", google.maps) this.map = new google.maps.Map(document.getElementById('myMap'), { center: {lat:61.180059, lng: -149.822075}, scrollwheel: false, zoom: 4 }) } } </script> <style scoped> #myMap { height:300px; width: 100%; } </style>
source share