yandex-maps-unofficial / vue-yandex-map

Yandex Maps Component for VueJS
MIT License
359 stars 103 forks source link

t.h is not a function ? #374

Open slpzc opened 2 years ago

slpzc commented 2 years ago
<template>
  <div id="map">
    <yandexMap
      ref="myMap"
      :coords="DEFAULT_COORDS"
      class="full-width"
      :zoom="MAP_ZOOM"
      :scroll-zoom="false"
      @map-was-initialized="ready"
    >
    </yandexMap>
  </div>
</template>

<script>
import { loadYmap } from 'vue-yandex-maps'

export default {
  name: 'indexYandexMap',
  data: () => ({
    API_KEY: 'мой ключ',
    DEFAULT_COORDS: [58.812924, 36.500804],
    MAP_ZOOM: 5,
    needToLoad: false
  }),
  created () {
    this.$axios
      .get(`https://api-maps.yandex.ru/2.1?lang=en_RU&apikey=${this.API_KEY}`)
      .then(() => {
        this.needToLoad = true
      })
      .catch(() => {
        this.needToLoad = false
      })
  },
  async mounted () {
    await loadYmap({
      apiKey: this.API_KEY
    })
  },
  methods: {
    ready () {
      const map = this.$refs.myMap.myMap
      map.controls.remove('rulerControl')
      map.controls.remove('geolocationControl')
      map.controls.remove('trafficControl')
      map.controls.remove('typeSelector')
      map.controls.remove('fullscreenControl')
      map.controls.remove('searchControl')
    }
  }
}
</script>

<style scoped>

</style>

В итоге получаю t.h is not a function. Как решать?

artemryskal commented 2 years ago

Посмею предположить, что вы должны использовать аргумент метода "ready", вместо this.$refs

alex-wdmg commented 2 years ago
      methods: {
                ready (map) {
                    //const map = this.$refs.myMap.myMap
                    map.controls.remove('rulerControl');
                    map.controls.remove('geolocationControl');
                    map.controls.remove('trafficControl');
                    map.controls.remove('typeSelector');
                    map.controls.remove('fullscreenControl');
                    map.controls.remove('searchControl');
                }
      }