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.

Sub-component inside v-popup and v-tooltip

See original GitHub issue

Hi @KoRiGaN,

Is it possible to use sub-component inside the content of v-popup and v-tooltip, instead of pure HTML string inside the content property?

So we can do this kind of stuff:

<div id="app">
  <v-map :zoom="zoom" :center="center">
    <v-tilelayer :url="url" :attribution="attribution"></v-tilelayer>
    <v-marker :lat-lng="marker">
      <v-popup>
        <button @click='counter += 1'>{{ some_content }}</button>
      </v-popup>
    </v-marker>
  </v-map>
</div>

Cheers, Tortue Torche

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mtdavidsoncommented, May 24, 2017

@tortuetorche I was trying to do the same thing but couldn’t quite figure it out. I ended up creating a new component with properties. As you need to build up a string to pass to bindPopup. It might not be the best method but it did work.

<template>
</template>

<script>

    import eventsBinder from '../utils/eventsBinder.js';
    import propsBinder from '../utils/propsBinder.js';

    const events = [
        'add',
        'remove',
        'popupopen',
        'popupclose',
        'tooltipopen',
        'tooltipclose'
    ];

    const props = {
        content: {
            default: '',
        },
        thumbnail: {
            default: '',
        },
        rating: {
            default: 0,
        },
        link: {
            default: ''
        }
    };

    export default {
        props: props,
        computed: {
            // a computed getter
            popupContent: function () {
                // There is probably a better way to do this
                return `
                    <div class="media">
                      <div class="media-left">
                        <img src="${this.thumbnail}" alt="" height="72" width="72">
                      </div>
                      <div class="media-body">
                        <a href="${this.link}"><h6 class="media-heading">${this.content}</h6></a>
                        Rating: <b>${this.rating}</b>
                      </div>
                    </div>
                `;
            }
        },
        mounted() {
            this.mapObject = L.popup();
            eventsBinder(this, this.mapObject, events);
            propsBinder(this, this.mapObject, props);
            if (this.$parent._isMounted) {
                this.deferredMountedTo(this.$parent.mapObject);
            }
        },
        beforeDestroy() {
            if (this.parent.getPopup()) {
                this.parent.unbindPopup();
            }
        },
        methods: {
            deferredMountedTo(parent) {
                this.parent = parent;
                parent.bindPopup(this.popupContent);
            },
            setContent(newVal, oldVal) {
                if (newVal) {
                    this.parent.bindPopup(this.popupContent);
                } else {
                    if (this.parent.getPopup()) {
                        this.parent.unbindPopup();
                    }
                }
            },
        }
    };
</script>
0reactions
punkmapcommented, Jun 20, 2018

Nice feature.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sub-component inside v-popup and v-tooltip #35 - GitHub
Hi @KoRiGaN, Is it possible to use sub-component inside the content of v-popup and v-tooltip, instead of pure HTML string inside the content ......
Read more >
Controlling tooltips & pop-up menus with components in React
1. Open the tooltip. react tooltip popup menu list element. Connecting the tooltip component to an element.
Read more >
Using v-tooltip on custom (non native) component
I have tried wrapping <custom-component /> in a div but it isn't working. Below is sample code to get the gist. <v-tooltip> <template...
Read more >
Tooltip | Components - BootstrapVue
Easily add tooltips to elements or components via the component or v-b-tooltip directive.
Read more >
Tooltip component — Vuetify
The v-tooltip component is useful for conveying information when a user hovers over an element. You can also programmatically control the ...
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