D
D
dicem2020-02-17 14:35:56
Yandex maps
dicem, 2020-02-17 14:35:56

Why is ymaps.ready() not working?

hello script.

<script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU&amp;apikey="some_api_key"></script>

is loaded outside of the Vue context, I use ymaps.ready() to test the loading of the API
...
mounted() {
            ymaps.ready({
                successCallback: () => {
                    this.yaMapInit()
                }
            })
},
...
methods: {
...
yaMapInit() {
                let id = this.forId

                try {
                    this.SuggestView = new ymaps.SuggestView(id, {
                        provider: { suggest: (...args) => this.suggest(...args) },
                        boundedBy: this.bounds[this.brandCode],
                        container: document.getElementById(id + '-container'),
                        results: 50
                    })

                    this.SuggestView.events.add('select', e => {
                        this.geoValue = JSON.parse(e.get('item').jsonData).city
                        localStorage.setItem('location.city', JSON.parse(e.get('item').jsonData).city)
                    })

                    console.log('yamaps init')
                } catch (e) {
                    console.log(`yamaps init error: ${e}`)
                }
            },
...
}


And every time the page is loaded for the first time, I get an init error.
ymaps.SuggestView is not constructor
What could be the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question