Utilizing Vue to create a button within a popup window

Utilizing the vue2-google-maps package, I have created a custom popup. Within this custom popup, there is a button that is intended to open a new popup in place of the existing one.

Here is the HTML code:

<gmap-info-window
  :options="infoOptions"
  :position="infoWindowPos"
  :opened="infoWinOpen"
  @closeclick="infoWinOpen=false"
>
  <div v-html="infoContent"></div>
</gmap-info-window>

For the first popup, here is the JavaScript code:


    toggleInfoWindow: function (marker, idx) {
        this.infoWindowPos = marker.position;
        this.activeMarker = marker;
        this.infoContent = this.getInfoWindowContent(marker);

        // Check if it's the same marker that was previously selected, if yes then toggle
        if (this.currentMidx == idx) {
          this.infoWinOpen = !this.infoWinOpen;
        }
        // If it's a different marker, set the info window to open and reset the current marker index
        else {
          this.infoWinOpen = true;
          this.currentMidx = idx;
        }
      },

      getInfoWindowContent: function (marker) {
        return (`<div class="card">
  <div class="card-image">
    <figure class="image is-4by3">
      <img src="https://bulma.io/images/placeholders/96x96.png" alt="Placeholder image">
    </figure>
  </div>
  <div class="card-content">
    <div class="media">
      <div class="media-content">
        <p class="title is-4">${marker.name}</p>
      </div>
    </div>

    <div class="content">
      ${marker.description}
      <br>
      <time datetime="2016-1-1">${marker.date_build}</time>
       <button @click="getSecondPopUp">Get second popup</button>
    </div>
  </div>
</div>`);
      },

    getSecondPopUp: function () {
        console.log("why don't you work?");
}

The issue arises when clicking on the button as the second method fails to execute. Can anyone shed some light on why this might be happening and how to resolve it?

Thank you in advance.

Answer №1

v-html only displays raw HTML code. When utilizing the getInfoWindowContent method to return HTML templates in Vue, it should be rendered directly by a Vue component (especially when using webpack as the templates are likely compiled with vue-loader, not at runtime).

If you are working with the vue2-google-maps package and want to achieve your desired result, avoid using v-html. Instead, insert the Vue template source code directly within <gmap-info-window>. Replace any instances of ${marker.description} string interpolations with Vue template interpolations like {{ activeMarker.description }} (making sure that activeMarker is defined beforehand in the component's data object for reactivity and rendering in the template). Consider using v-if to manage visibility based on whether activeMarker is null or not (unless the gmap-info-window component omits rendering its slot if the opened prop is false).

In general, it's advisable to refrain from using v-html due to the potential security risks such as cross-site scripting (XSS).

Answer №2

You might want to explore using a Vue-powered popup instead of the default one provided by maps. Check out this alternative solution here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the most effective method for implementing a debounce effect on a field in React or React Native?

Currently, I am working on implementing a debounce effect in my useEffect. The issue is that the function inside it gets called as soon as there is a change in the input value. useEffect(() => { if (inputValue.length > 0) { fn(); ...

Express Validator: The Art of Isolating Validation Logic

This query is more focused on structuring code rather than troubleshooting bugs or errors. I am currently tackling request body validation, where the JSON structure looks like this: { "title": "Beetlejuice", "year&qu ...

Changing the caret position in a contenteditable div using HTML React

In a recent project I worked on, I included contenteditable divs. Whenever the enter key is pressed within one of these divs, it splits into two separate contenteditable divs. However, after React re-renders the components, the caret tends to go to the beg ...

What is the role of the app.use method in ExpressJS in handling URL redirects that end with a "/"?

This script automatically redirects URLs that end with a "/" to the same URL without it. For example, if a user visits http://localhost:3000/about/, they will be directed to http://localhost:3000/about. This ensures that image URLs and other HTML file refe ...

Trigger the Modal once the navigation step is completed

When navigating to a new page, I need to wait for the navigation process to complete in order for the modal template to be properly displayed on the destination page. public onOpenModal(item) { this.router.navigate([item.link]).then(() => { this. ...

Having trouble getting the auto complete feature to work in AngularJS with jQuery

I have been attempting for the last 5 hours without any success... Below is the code snippet: Within View: <input type="text" ng-model="foo" auto-complete/>Foo = {{foo}} Inside the controller: myapp.directive('autoComplete', functi ...

Newbie struggling with executing JavaScript in Visual Studio Code

Hey there! I'm new to coding and have been struggling for the past couple of hours trying to get a simple JavaScript code to run on VSC. Can anyone lend a hand in helping me set up my sandbox correctly? Here's a snapshot for reference: https://i ...

Gather information from every user and display their user ID in an HTML table, allowing for updates through a button

Can anyone help me create a table like the one shown here: The table should fetch data from my firebase database. Here is the structure of my requests database: . I've been trying to modify some code I found in a previous question. However, as you c ...

How to set DIVS to be hidden when the page first loads

I am currently working on a project where I need to use JavaScript to hide certain <div> elements when the page loads. I have also included jQuery in my code. Below is what I have tried so far: $(document).ready(function() { hide(); function hid ...

Ways to ensure the text on my website scrolls into view as the user navig

Is there a way to have my text show up as I scroll? I came across this , but I'm interested in how it actually functions. I saw a similar inquiry before, but it doesn't make sense to me. Can someone please explain or provide some examples on how ...

Is it possible to extract information from a string that includes HTML code within a browser using CSS selectors without actually generating the DOM elements?

I've been struggling with this basic task for hours. I can't find any libraries that work and none of the questions here address my specific issue. Here's what I need to do: The entire page's markup is in a string format. I must use ...

The response from Axios is returning HTML content instead of the expected object

I am experiencing an issue with Axios in my project. I am developing a SPA web app using Laravel 6 (with package SPARK) and VueJS (version 2). In one of my Vue components, I am trying to retrieve data from my database by making a GET request to an API URI ...

While loop not yielding immediate result with asynchronous function

As a beginner in Node.js, I have successfully connected an LCD Panel and a 4x4 Membrane matrix keypad to my Raspberry Pi. Using Node.js, I have programmed them to work together. My goal is to have the LCD panel immediately display any key pressed on the ke ...

Is it possible to minify HTML in PHP without parsing JavaScript and CSS code?

After finding a solution in this discussion, I successfully managed to 'minify' HTML content. function process_content($buffer) { $search = array( '/\>[^\S ]+/s', // eliminate spaces after tags, except for ...

receiving a pair of components instead of just one

Here is the code for router.js: import React from 'react'; import { Route } from 'react-router-dom'; import CommentList from './containers/commentview'; import CommentDetalList from './containers/commentdetailview'; ...

Tips for determining the presence of a query string value using JavaScript

Is there a way to detect the presence of q= in the query string using either JavaScript or jQuery? ...

React code to automatically scroll to the top of the page when the user clicks the

Whenever the URL changes or the page is reloaded in my project, I need it to scroll back to the top. While most scenarios work fine, I'm encountering an issue with the browser's back button. Despite a change in the pathname, the page fails to scr ...

React Hooks: Issue with UseRef not detecting events from Material UI Select component

I'm currently utilizing React Hooks in my project. I am attempting to trigger an onclick event using the useRef hook. const component1: React.FC<Props> = props { const node =useRef<HTMLDivElement>(null); const ClickListe ...

There seems to be an issue with the React Hooks edit form where it is not selecting the record to edit. Although the currentId is correct

I have a simple CRUD React Hooks app with an ASP.NET Core Web API. The Courses component displays a list, but when I click on a link to edit a particular course, the form shows up with empty fields. Here is the JSX for the Courses component: import React, ...

Load a webpage using javascript while verifying permissions with custom headers

Seeking guidance as a novice in the world of JavaScript and web programming. My current project involves creating a configuration web page for a product using node.js, with express serving as the backend and a combination of HTML, CSS, and JavaScript for t ...