I
I
Ilya Kochkin2021-11-28 12:03:11
Yandex maps
Ilya Kochkin, 2021-11-28 12:03:11

How to add point on yandex map in Vue 3?

Good afternoon, there is a problem when adding a point on the map, if we use vue 3, I mean that if we do the initialization of the map through

data(){
return {
map:null
}
},
methods:{
    initMap() {
       this.map = new ymaps.Map(this.$refs.map, {
        center:this.center,
        controls: [],
        zoom: this.zoom
      });
},
  mounted() {
    this.initMap()

  }

and then I try to add a point on the map through

this.map.geoObjects.add(myPlacemark)
then an error occurs
0H-bNDFcYyI.jpg?size=757x171&quality=96&sign=50436dc77e7ca59c9632051ce670a8d6&type=album
if I do not through this but through a variable, then no error occurs and everything is fine
let map;
...
initMap() {
       map = new ymaps.Map(this.$refs.map, {
        center:this.center,
        controls: [],
        zoom: this.zoom
      });

, for some reason I think that the problem here is due to proxy vue3, but I don’t know how to solve this problem

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-11-28
@mr_Koch

I think that the problem is because of the proxy

Then try to get the original object and work with it already: Or don't make it reactive initially:
Vue.toRaw(this.map).geoObjects.add(placemark);
this.map = Vue.markRaw(new ymaps.Map(this.$refs.map, {
  ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question