question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Acces to child property/methods

See original GitHub issue

Hello,

I’m trying out Vuejs these days. I’m not a font-dev expert though …

Here is my question : I’m working on a project with an API serving geo_shapes through json format. I have all my polygons displayed. In order to understand the underlying mechanism, I’m wondering how to proceed to change the polygon fillColor on mousever for highlighting. What is the recomended way to make this done and how can I access the setFillColor in my Vue component ?

Here is chunks of component code :

<template>
<v-map id="leaflet">
    <v-tilelayer></v-tilelayer>

    <v-polygon v-for="area in areas" :key="area.id"
                           :lat-lngs="area.geometry.coordinates"
                           @l-dblclick="goto_sublevel(area)"
                           @l-mouseover="change_color()">  <!--???-->
        <v-popup :content="area.name"></v-popup>
    </v-polygon>

    <v-polygon v-for="area in parent_area" :key="area.id"
                           :lat-lngs="area.geometry.coordinates" :color="'#ff6056'"></v-polygon>
</v-map>
</template>

<script>
import Vue2Leaflet from 'vue2-leaflet';

export default {

        components: {
            'v-map': Vue2Leaflet.Map,
            'v-tilelayer': Vue2Leaflet.TileLayer,
            'v-polygon': Vue2Leaflet.Polygon,
            'v-popup': Vue2Leaflet.Popup
        },

        methods : {
        goto_sublevel: function (level) {
                // do something to retrieve data of next geographical level ...
                },
        change_color: function (?) {
                // ??? is it here that magic should happen ?
        },

}


</script>

Anyway, I found your api clear enough to had some fun with leaflet. Thanks for your job ! 😉

Dithyrambe

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14

github_iconTop GitHub Comments

1reaction
dithyrambecommented, Nov 14, 2017

Nice !

Thanks all for your perfect explications ! I’ll go for the setStyle method. Looks cleaner to me. However, all insights were welcome. –> issue solved 😄

And thx again for all the hard work on vue2-leaflet !

Dithyrambe

1reaction
KoRiGaNcommented, Nov 14, 2017

Hi @dithyrambe,

In vue2-leaflet you can set fillColor / opacity / weight etc the way 3RedM0 explained and this is the “more vue2-leaflet” approach: using reactivity of vue with leaflet.

If you want to access vue2-leaflet object and methods instead of using the property you can see this example. If you want to access leaflet object and methods instead you can see this example.

Let me know if these examples solved your issue.

Cheers,

Mickaël

Read more comments on GitHub >

github_iconTop Results From Across the Web

Access child property from parent scope - php - Stack Overflow
Take a look at an article about visibility. Basically, you cannot access parent's private properties/methods nor can the parent access its child's.
Read more >
How to Access Child-class Methods from Parent-class in Python
You can access child methods from the parent. The example shows a real-time scenario, and it's helpful for interviews.
Read more >
How to access child component properties in Vue.js 3
Useful tip to access methods and functions from child components ... Some of the Vuejs component properties we can access include functions, ...
Read more >
Accessing child properties from parent classes / abstract ...
MATLAB defines a protected property to mean accessible from the class defining the property and all child classes (but NOT any parent classes)....
Read more >
Is it possible to access child class with parent reference? - Quora
yes it is possible to hold child object with parent reference.. it is also a polymorphism and we generally use this approach when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found