-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


[ ] C Google Maps API VueJs2

, 23 2017 . 23:03 +
BRAINKIT 23:03

C Google Maps API VueJs2

  • Tutorial
Google Maps API . .

(), vuejs.

, hello word VueJs2 es6. :

API


API . , google maps api index.vue



"[YOUR API KEY]" Google Maps API.
google , .


components, googleMap.vue index.vue hello word .

googleMap.vue:



, id name , .

. googleMap.vue:



: google-map, name, data , mounted methods .

:



!

, index.vue:




google-map, . import index.vue components.

, , , new google.maps.Map


. , mounted, , div. mounted new google.maps.Map. div. zoom level :

export default {
        name: 'google-map',
        props: ['name'],
        data: function () {
            return {
                map: ''
            }
        },
        computed: {
            mapMarkers: function () {
                return this.markers
            }
        },
        mounted: function () {
            const element = document.getElementById(this.name)
            const options = {
                zoom: 14,
                center: new google.maps.LatLng(59.93, 30.32)
            }
            this.map = new google.maps.Map(element, options)
        },
        methods: {}
    }

:

image


, , !

, . , , props:

data: function () {
   return {
       map: '',
       markers: [
           {
               position: {
                   latitude: 59.93,
                   longitude: 30.32
               }
           },
           {
               position: {
                   latitude: 59.928,
                   longitude: 30.32
               }
           }
       ]
   }
}

2 , position . position, , title.

, mounted , new google.maps.Marker:

mounted: function () {
            const element = document.getElementById(this.name)
            const options = {
                zoom: 14,
                center: new google.maps.LatLng(59.93, 30.32)
            }
            this.map = new google.maps.Map(element, options)
            this.markers.forEach((marker) => {
                const position = new google.maps.LatLng(marker.position.latitude, marker.position.longitude)
                marker.map = this.map
                marker.position = position
                new google.maps.Marker(marker)
            })
        }

position , map position, new google.maps.Marker(marker)

!

:

image

:







eslint, eslint-disable/eslint-enable mounted, google.maps.

index :





.
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/338568/

:  

: [1] []
 

:
: 

: ( )

:

  URL