Unable to trigger @click event on nuxt-link component within Nuxt 3

As per a Nuxt 2 question on Stack Overflow, it was suggested that the following code should prevent nuxt-link from navigating to a new page:

<nuxt-link :to="`/meet`" class="group font-normal" @click.native="event => event.preventDefault()" event="">

However, it does not work as expected. The function defined in the @click attribute is not being executed and Nuxt still navigates to the /meet URL.

Any suggestions on how to properly handle @click events on a Nuxt 3 link?

Answer №1

Consider incorporating the prevent modifier and eliminating the :to prop:

<nuxt-link  class="group font-normal" @click.prevent="yourEventHandler" event="">

Afterwards, utilize this.$router.push() within your event handler

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

Sending an array from the server to the client using Node and Express during page loading?

I am utilizing Node and Express in my project. The application fetches data from a remote database on page load and sends it to a handlebars template server-side. However, I would like this JSON data to also be accessible for client-side interactions. How ...

Error in VueJS: Variable not defined

I've hit a roadblock with this problem and could use some assistance. After searching for similar issues, I was unable to find a suitable solution. The problem is straightforward: my components are unable to access my variables.scss file unless it&apo ...

Navigating the grid layout in Material UI can be tricky to

I'm struggling to grasp the concept of the grid system in material UI. Within my grid container, I have two grid items that I want to be centered and occupy the entire width. The button element appears centered, but the typography element does not. A ...

Avoiding multiple ajax requests due to multiple clicks

I have a blog on WordPress that has a jQuery code allowing users to click a bookmark link to save the post as a bookmark. Each post displays a total bookmark counter in this format: "Bookmarked (5)". The issue is that when a user clicks multiple times on t ...

Unable to utilize the attribute selector feature within Cypress

Here is my HTML snippet: <label class="email"> Email <input data-test="email" type="text" v-model="curMember.email_address"> </label> When attempting to use an attribute selector in my cypress test with the following 'GET' ...

Only the initial value is being processed in the for loop using Javascript

I am having issues trying to sum the values within a for loop sourced from my Django database using JavaScript. Currently, when I iterate through the loop, only the first value in the array is returned. I need assistance in finding a solution that allows ...

Having trouble getting the Underscore.js template to function correctly with JSON data

Hello there! I have some PHP code $arr = array("title"=>"sample Title", "body"=>"151200"); echo json_encode($arr); The data output is: {"title":"test Title","body":"151200"} When I attempt to use this JSON output in Underscore, I encounte ...

What is the best way to utilize a promise for a singular variable?

In my code, I have a requirement where I need to make two HTTP requests. The second request is dependent on information retrieved from the first request. Initially, the first request sets the variable 'amount' which is later used in the second re ...

React TypeScript - creating a component with a defined interface and extra properties

I'm completely new to Typescript and I am having trouble with rendering a component and passing in an onClick function. How can I properly pass in an onClick function to the CarItem? It seems like it's treating onMenuClick as a property of ICar, ...

Check an image preview prior to uploading through FileReader, rotates the image

After browsing through numerous posts about viewing images before uploading, I stumbled upon an intriguing solution that claimed to be simple using FileReader: function displayImage(input) { if (input.files && input.files[0]) { var reader = ne ...

Utilize Javascript to interpret a structure that resembles JSON

My data resembles JSON, with columns and names listed: columns: [ { allowNull: false, autoEnterSubType: 0, autoEnterType: 2, creationOrderIndex: 0, dataType: 4, databaseSequenceName: "seq_admintraties_adminratie_id", flag ...

Display additional tiles within a compact container

I'm attempting to replicate the user interface used by foursquare! Positioning the map slightly off center like they have . I've figured out how to do one part but struggling with the second part. Initially, I loaded the map in a small div (t ...

Issue with AngularJS expression not functioning as expected in Chrome for setting input type to "file"

I have encountered a strange bug while working on an Angular form builder application. The issue arises in Chrome when I try to dynamically set the input type based on a variable. Surprisingly, this method works perfectly for all input types except "file", ...

Creating a dynamic image slider that smoothly glides across a webpage

I've been working on a carousel (image slider) for my website and I need some help. Specifically, I want to reposition the entire slider slightly to the left on the webpage. You can see the slider in action on this site: and I also created a jsfiddle ...

The Mystery of jQuery Isotope Plugin: Why Can't I Add "display:none" Inline?

I'm currently in the process of integrating Isotope into my latest Wordpress theme. However, I've encountered an issue where it's not appearing on the page due to some external factor adding an inline style (display:none) to the main isotope ...

What is the best way to apply changes to every class in JavaScript?

Check out this HTML and CSS code sample! body{ font-family: Verdana, Geneva, sans-serif; } .box{ width: 140px; height: 140px; background-color: red; display: none; position:relative; margin-left: auto; margin-right: auto; } .bold{ font ...

Issue: A SyntaxError is triggered due to an unexpected termination of the JSON input while utilizing the fetch()

I encountered an issue while working on sending JSON between a Go API server and a React front-end. The error message I received was: Error: SyntaxError: Unexpected end of JSON input The specific line where the error is occurring is Line 25, which contai ...

Vue Checkboxes - Maintain selection unless a different checkbox is selected

I have implemented a checkbox system with radio button behavior, but I am facing an issue where I want to keep the checkbox checked until another checkbox is selected (which will then uncheck the first one). I do not want the ability to deselect the checkb ...

Obtain the API key from the .env file and incorporate it into the boot files in Qu

Extract the value of GOOGLE_MAP_API variable from the .env file and pass it to gmap-vue.js located in the boot/ directory It works fine when I directly use the key like this load: { key: 'AIzaSyCw9Txxxxxxxxxxxxx', ... } However, I w ...

Displaying content conditionally - reveal a div based on user selection

I have a dropdown menu and need to determine whether to display a specific div using the value selected via v-if. <select class="custom-select custom-select-sm" id="lang"> <option value="1">English</option> <option value="2">Sv ...