Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
When passed to vue component, mapbox object cant find functions like getLayoutProperty() or setFilter()

Using mapbox-gl-js 2.8.2

To setup the map I have to fetch data from an api. Given that, I have to init mapbox in the then and, since I need the map object in my vue component, I have to init Vue in the then too.
But since I do that, every time I call a function on the map object (i.e. map.setFilter()), I have TypeError: map.setFilter is not a function.

The code looks like this :

<head>
    <script src="https://api.mapbox.com/mapbox-gl-js/v2.8.2/mapbox-gl.js"></script>
    <link href='https://api.mapbox.com/mapbox-gl-js/v2.8.2/mapbox-gl.css' rel='stylesheet'/>
</head>
<body>
    <div id="map"></div>
    <app :map="this.map"></app>

    <script>
        Vue.component('app',{
            props:['map'],
            template: `
                <div id="app">
                    <button v-on:click="logFilter"></button>
                </div>
            `,
            data:function(){
                return {};
            },
            methods:{
                logFilter:function(){
                    console.log(this.map.setFilter('land',["any"]))
                }
            }
        }
    </script>
    <script>
        fetch('some/api/url')
            .then((res)=> {
                res.json()
                    .then(cityData=>{
                        mapboxgl.accessToken = 'my_token'
                        let map = new mapboxgl.Map({
                            container: 'map',
                            center: cityData.location,
                            zoom: cityData.zoom
                        })
                        const vue = new Vue({
                            el : 'app',
                            data:{
                                map : map,
                            }
                        });

                    });
            });
    </script>
</body>

When the button is clicked, the console will show the error TypeError: map.getStyle is not a function.

This issue has occured since I make the vue declaration in the then so I guess it's an issue with vue and async functions but I can't find anything about that online.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda