Integrating Google Maps in vue.js

后端 未结 6 1236
情书的邮戳
情书的邮戳 2020-12-08 15:24

I\'ve been trying to initialize a Google map on my vue.js project while including the script :



        
6条回答
  •  情歌与酒
    2020-12-08 15:51

    I'd suggest using npm google-maps instead of adding a script in index.html. You might not need to call google-maps API in every pages, and I'd say it's better to use Webpack properly. You can use npm install google-maps

    import GoogleMapsLoader from 'google-maps'
    
    mounted: function () {
      GoogleMapsLoader.load(function(google) {
        let map = new google.maps.Map(document.getElementById('map'), {
          zoom: 15,
          center: position
        })
      })
    }
    

提交回复
热议问题