Nuxt's build process can disrupt VueJS events

Running a production environment for my nuxtjs application has caused some issues with VueJS functionality, especially with DOM events. Interestingly, the development mode works perfectly fine, albeit slower than the production mode due to lack of minification and compilation.

  • @click events are not triggering their intended actions
  • .prevent is not preventing anything

Here's an example section from my source code that is not functioning as expected.

The @click event handlers that should switch the view are not working.

When hitting enter to trigger v-on:keydown.enter="login", it does not get prevented and the form gets submitted as a GET request to the same page (the URL displays the GET ?variables).

Upon inspecting the HTML code in the browser for any logged warnings or errors, there seem to be none, and the server side logs also show no issues.

Additionally, the <button> elements with @click attached to execute login or signup methods do not seem to have any associated events, essentially behaving only as static HTML.

After running nuxt build via npm run build on my production server, there are no visible errors or warnings.

<template>
<div class='card'>
    <div class='tabs 2-col'>
        <span :class="{active : view != 'signup'}" @click="view = 'login'">
            Login
        </span>
        <span :class="{active : view == 'signup'}" @click="view = 'signup'">
            Sign Up
        </span>
    </div>
    <div class='card-body'>
        <form v-show="view == 'login'" v-on:keydown.enter="login" novalidate>
            <!-- my other html -->
            <button @click.prevent="login">Login</button>
        </form>
        <form v-show="view == 'signup'" v-on:keydown.enter="signup" novalidate>
            <!-- my other html -->
            <button @click.prevent="signup">Sign Up</button>
        </form>
    </div>
</div>
</template>
<script>
export default {
    data : function(){
        return { view : 'login'};
    },
    methods : {
        login: function(){
            // my functionality
        },
        signup:function(){
            // my functionality
        },
    }
}
</script>

Your assistance would be greatly appreciated! I've been struggling with this issue for hours now.

Answer №1

data attribute needs to be a function that returns the object. Here is an example of how you can achieve this:

data: function () {
  return {
    view: 'login',
  }
}

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: Unable to execute $(...).stellar since it is not a recognized function

Having some trouble implementing the stellar plugin. I've included all the necessary js, but keep getting an error in the dev tools console: 'Uncaught TypeError: $(...).stellar is not a function'. Here's what I have in the head tags: ...

Receive alerts in Swift from WKWebView when a particular screen is displayed in HTML

Check out this sample HTML file I have. I'm currently using the WKWebView to display this HTML. My goal is to receive a notification in our Swift code when the user finishes the game and the "high score" screen appears, so we can dismiss the view and ...

Is there a way to utilize immediate: true in watch while also accessing values from the created hook in Vuejs?

My current watch statement looks like this: watch: { $route: { immediate: true, handler(newVal) { if (some condition ...) { this.getItems() } }, }, }, However, upon the initial page l ...

The Angular project failed to run properly following the ng build command

Just started working with Angularjs 2 and encountered an issue after running ng build. The compiled files were placed in the dist folder, but when I checked the index.html file within that folder, all the scripts had missing references even though they w ...

Modify JSON date format to a shorter version using the first 2 letters of the month and the year

Looking to convert date values in a JSON array from "December 2016" format to "D16". Hoping to accomplish this using Regex, any assistance would be greatly appreciated. [["November 2016","December 2016","January 2017","February 2017","March 2017"],["tot ...

What is the process to retrieve a function from a router javascript file using node.js?

Dealing with a web application that is not my own, I now have the task of sending out one hundred emails. Unfortunately, the code is poorly documented and written, which means I need to test it to figure out what I can and cannot do. However, I'm uns ...

Creating operations in Angular using the Model View Controller (MVC)

What is the procedure for performing an Add operation in MVC using Angular? var addProductModule = angular.module("addProductModule", []); addProductModule.factory("addProductService", ['$http', function ($http) { return { function savePro ...

script loop causing an embedded form

While trying to include a Hubspot embedded form on a page using a script, I encountered an issue. I utilized onMounted to ensure the form is displayed correctly. However, upon leaving and re-entering the component where the form is located, an additional b ...

"Encountered an Unspecified Variable Error in executing document

Every time I open my Chrome console, it keeps showing an error message saying "toggleOnlyRelatedPosts is not defined". The script I'm working on doesn't seem to be functioning properly. I've added so many variables that I now feel lost and o ...

Using arguments within Vue to conditionally bind events

When attempting to conditionally bind an event method in the template, I encounter some issues. In the template: <div class="survey-card__option radio" :class="data.column ? data.column : ''" v-for='(option, index) ...

Error message appears when trying to render a shallow mock of a React.Component that extends MyInterface with any type

Encountering an Issue with Component Mocking When attempting to mock a component, I am receiving the following error message: "Conversion of type '{ props: { index: number; AssignmentTitle: string; AssignmentDescription: string; AssignmentUtilizedHou ...

Vue - Pages fail to load post-build

I have a Vue project built with vite. During debugging, everything works fine. However, when I build it for production and try to preview it, the Chrome window hangs loading indefinitely. There is nothing shown on the console. Is there a way to capture ...

Single array returned by observable

Issue: I am looking for a way to consolidate the multiple arrays returned individually into a single array. Solution: fetchAllRiders() { var distanceObs = Observable.create(observer => { this.http.get(this.API + '/driver/all').map(res = ...

Is it possible to adjust the popup width based on the child classes?

<span class="grandparent"> <span class='parent'> <span id="popUP" class="child1"> Some content for popUP </span> <!-- 1st child has width of 390px--> </span ...

What is the method for accessing the locale and messages of the IntlProvider within a component?

My index.js file includes the following code: import trFi from './translations/fi_FI.json'; import trSv from './translations/sv_SE.json'; ReactDOM.render( <IntlProvider locale={my_locale} messages={{ fi: trFi, sv: trSv } ...

What is the solution for fixing an error that says "There is no 'style' property on the 'Element' type"?

I'm struggling to fix an error in my JavaScript code. I created a script to display a tab indicator when a tab is clicked, but I keep getting the error message: "Property 'style' doesn't exist on type 'Element'". The tabs them ...

Reset the AJAX object using jQuery

Currently, my code looks like this: object1 = $.ajax({ .. .. }); If an error occurs, I would like to have the ability to restart the ajax request. For instance, if the user's connection is lost, I want to be able to easily call the same ajax again w ...

Using the onKeyUp and onKeyDown functions to detect when the spacebar key is pressed

Is there a way for my function to be triggered by either clicking a button or pressing the spacebar? I have managed to make it work partially, but it's not quite right. This is the function in question: const showText = () => { const x = Toug ...

Develop interactive, reusable custom modals using React.js

I am currently working on creating a reusable modal: Here is my component setup: class OverleyModal extends Component { constructor(props) { super(props); } openModal = () => { document.getElementById("myOverlay").style.display = "blo ...

Error: The module '/@modules/vue.js' does not export a 'default' value as requested by the syntax

I'm encountering an issue with Vee Validate form validation in Vue.js. As a beginner, I am struggling to grasp the import syntax. After installing vee-validate using npm i vee-validate --save and placing it in my node_modules directory, I proceeded to ...