How can I create a menu of buttons in Vue that open individual windows with unique URLs when clicked?

Javascript Code:

function InitializeVue() {
    var vueOptions = {
        el: '#activeEvents',
        data: {
            activeEvents: []
        }
    };

    vueInstance = new Vue(vueOptions);
}

HTML Code:

<table id="activeEvents">
    <tr v-for="event in activeEvents">
        <td>{{event.serviceType}}</td>
        <td>{{event.loc}}</td>
        <td>{{event.dateLastUpdated}}</td> 
        <td>
            <!-- Include a button here that triggers window.open() with the URL "Update.aspx?id={{event.eventID}}" -->                              
        </td>
    </tr>
</table>

I have faced difficulties as it's not possible to directly inject attributes from a Vue object into an HTML element, and I encountered issues referencing the Vue object from within a script due to it being undefined.

If you are considering downvoting, please provide feedback on why. Thank you!

Answer №1

To trigger the

window.open('https://yourwebsite.com/Update.aspx?id=' + event.eventID)
function, you can simply use the @click handler for the button.

Here is an example to help illustrate the concept:

(Since Stack Overflow does not allow window.open in a Snippet, you can view this CodePen Mirror here)

let app = new Vue({
  el: "#app",
  template: newAppTemplate(),
  data: {
    activeEvents: [{
        serviceType: "website1",
        loc: "loc1",
        dateLastUpdated: Date.now(),
        eventID: "google.com"
      },
      {
        serviceType: "website2",
        loc: "loc2",
        dateLastUpdated: Date.now(),
        eventID: "duckduckgo.com"
      },
      {
        serviceType: "website3",
        loc: "loc3",
        dateLastUpdated: Date.now(),
        eventID: "yahoo.com"
      },
    ]
  }
});

function newAppTemplate() {
  return `
    <table id="activeEvents">
        <tr v-for="event in activeEvents">
            <td>{{event.serviceType}}</td>
            <td>{{event.loc}}</td>
            <td>{{new Date(event.dateLastUpdated)}}</td> 
            <td>
                <button @click="window.open('https://' + event.eventID)">Open</button>
                <!-- want a button here that executes window.open() with URL "Update.aspx?id={{event.eventID}}" -->
            </td>
        </tr>
    </table>
`
}
table,
tr,
td {
  border: 1px solid black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
<div id="app"></div>

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

Error on GoDaddy server caused by a trust level set to 'Full'

After uploading my website to a GoDaddy web server, I encountered an error that is not present when running the site on localhost. Configuration Error Description: The error occurred while trying to process a configuration file necessary for handling ...

The harmonious combination of Opera and XMLHttpRequest creates a

Coming from Russia, please excuse any mistakes in my English. I am trying to dynamically load the main page of my website using JavaScript, and I have written this script: <script type="text/javascript"> function httpGet(theUrl) { var xmlHt ...

Unable to trigger Vuejs click event when using v-if condition

I've encountered a strange issue. I'm attempting to trigger a method when an element is clicked in a v-for loop, but it doesn't seem to work when using v-if or v-show. Here's a sample of my HTML code: <div class="chosen-drop custom ...

"Exploring the power of Vue3's composition API in managing the

Trying to implement an accordion component in Vue 3, but encountering a strange comparison issue. I'm attempting to execute a function within the accordionitem - specifically the toggle operation. However, despite numerous attempts, I am unable to mo ...

What is the best way to align a box once another one has been placed?

I have integrated both Bootstrap and Masonry plugins into my website design. The issue I am facing is that the Masonry plugin box goes under the top Bootstrap bar. I tried adding a margin-top: 50, but this resulted in a horizontal scroll bar appearing. To ...

No entries found in the Nuxt/content module's array

<template> <div> <input v-model="searchQuery" type="search" autocomplete="off" placeholder="Search Articles" /> <ul v-if="articles.length"> ...

Displaying selected checkbox values in a URL with parameters using PHP and JavaScript

I am looking to extract the selected checkbox value and append it to the browser URL with a parameter name. Below is my HTML code: <div style="width:200px; float:left"> Price <div> <input type="checkbox" name="price" value="0-1 ...

Utilizing Vue to properly reference asset paths for background URLs

I recently developed a Vue application and I am currently trying to display an image as a background in a div element. I have found that using the following code snippet accomplishes this: background: url('~../assets/my_image.png'); However, I a ...

Detect when the Keyboard is hidden in React Native

On my screen, I have a date picker and a text input. In order to prevent awkward transitions, I need to hide the keyboard before displaying the date picker. Currently, I'm resorting to a workaround because I don't know how to trigger a callback ...

JSP checkbox functionality

I have been attempting to solve this issue since last night, but I am struggling and need some help. There are two pages, named name.jsp and roll.jsp. In name.jsp, there are two input text boxes and one checkbox. After entering data in the text boxes and ...

"Everything is running smoothly on one REST endpoint, but the other one is throwing a CORS error

I am currently working on a project that involves a React client app and a Django server app. The React app is running on port 9997 and the server API is on port 9763. While the frontend is able to access some APIs successfully, there are some APIs that ar ...

The issue arises when HTML tables with unique IDs are all displaying the same value from an AJAX callback

This situation has been incredibly frustrating for me!! Let me explain what's going on - I have a callback data coming from my AJAX post method that needs to be passed to seven different HTML tables. Although I successfully received the data from the ...

Create a log table specifically for tracking changes made to the drop-down menu

I need to create a Change log table that will track any changes made in the drop-down menu. For instance, I am working on a worksheet with a select menu called Results which includes options like Positive, Negative, Unknown. I want the system to log any ch ...

Show the "Splash" picture, then switch to a newly uploaded image and show it for a set amount of time

I am in the process of developing an HTML/JavaScript page that will showcase a splash image (splash.jpg) until it gets replaced by another image file called latest.jpg. Once this latest.jpg is displayed, I want it to remain on the screen for 90 seconds bef ...

How can I stop jQuery from repeatedly appending content every time I click the button?

Hey there, I have a question about calling a JSON array using jQuery. Every time I press the button, it loads the list again instead of multiplying. Here is the JSON array: [{"denumire":"Q Club"},{"denumire":"Carul cu Flori"},{"denumire":"La Rocca"}] And ...

Integrating Vue Router with a CFML (Lucee) server

I have a Vue Router set up that is working flawlessly for navigation using <router-link to="/test">test</router-link>, but when I manually type the URL into the browser like , it reloads the page and shows a 404 error. On the server-side, I ...

Elegant switch in jQuery

I am trying to use jQuery to create an animated toggle button. The toggle function is working correctly, but I am having trouble adjusting the speed and smoothness of the animation. After researching different methods and attempting to modify the values i ...

What is the best way to design a grid with various squares in React Native?

Here's the design I aim to achieve: I am looking to implement the above layout in react native and ensure it is responsive on all screen sizes. I attempted using flexbox but couldn't figure out how to make the boxes square shaped. The code provi ...

Creating a dynamic onclick function that depends on a variable passed from a while loop in PHP

If you're familiar with PHP, I have a scenario for you. Let's say there's a list of items generated using a while loop in PHP. Each item has a sub-list that should only appear when clicked on. I tried using the onclick function in jQuery but ...

Creating an array upon clicking and dynamically changing its class using AngularJS

Currently, I am developing a scheduling application where there are 2 individuals enrolled for 11 different dates. The functionality I am working on involves allowing the user to click on a month, which will then be added to an array and highlighted. If t ...