M
M
MOFO5562020-08-10 12:58:07
Vue.js
MOFO556, 2020-08-10 12:58:07

What could be the problem with 2gis map initialization for vue?

API is registered in head

<script src="https://maps.api.2gis.ru/2.0/loader.js?pkg=full"></script>


Prescribing a card
<div ref="cap" style="width:100%; height:100%"></div>


Initialization:
import DG from '2gis-maps'
    export default {
        data(){
            return{
                map: null
            }
        },
        mounted(){
            this.map = new DG.map(this.$refs.cap, {
                center: [36.165658, 51.801861],
                zoom: 13,
                minZoom: 10,
                fullscreenControl: false
            });
            DG.marker([36.165658, 51.801861], {
            }).addTo(this.map);
        },
        beforeDestroy () {
            if (this.map) this.map.remove()
        }
    }


The element is written but empty.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-08-10
@MOFO556

There is no guarantee that by the time your component is mounted, the 2GIS API will be loaded. So code located in mounted should be wrapped in DG.then.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question