@kentos

Как передать значение?

Здравствуйте, как из этого метода вывести в дата, currentCoords

mapCreated: function ($map) {
                let pointOnMap = new ymaps.Placemark([55.7204,37.6200], {}, {
                    draggable: true
                });

                $map.geoObjects.add(pointOnMap);
                this.map = $map;

                let coords = [55.7204,37.6200]

                pointOnMap.events.add("dragend", function (e) {
                    let coords = this.geometry.getCoordinates();
                    let currentCoords = coords[1].toFixed(6) + ',' + coords[0].toFixed(6);
                }, pointOnMap);
            },
  • Вопрос задан
  • 120 просмотров
Решения вопроса 1
potapchino
@potapchino
в начале метода пишите вот это:
mapCreated: function ($map) {
  const _this = this;
//   далее идет код
}


затем меняете let currentCoords на _this.currentCoords

в итоге должно быть вот так:
mapCreated: function ($map) {
  const _this = this
  
  let pointOnMap = new ymaps.Placemark([55.7204,37.6200], {}, {
    draggable: true
  });
  
  $map.geoObjects.add(pointOnMap);
  this.map = $map;
  
  let coords = [55.7204,37.6200]
  
  pointOnMap.events.add("dragend", function (e) {
    let coords = this.geometry.getCoordinates();
    _this.currentCoords = coords[1].toFixed(6) + ',' + coords[0].toFixed(6);
  }, pointOnMap);
}
Ответ написан
Пригласить эксперта
Ответы на вопрос 2
@nvdfxx
Senior Pomidor developer
this.dataCurrentCoords = currentCoords, не?
Ответ написан
Jossnix
@Jossnix
tester
заменить
let currentCoords = coords[1].toFixed(6) + ',' + coords[0].toFixed(6);

на
this.currentCoords = coords[1].toFixed(6) + ',' + coords[0].toFixed(6);


При условии, что в data объявлен currentCoords
data() {
    return {
        currentCoords: ''
    ...    
    }
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы