Issue with modal component triggering unexpected page reload

I'm encountering a strange issue with my modal in Vue.js. It only appears on a specific page named 'Item', but when I click on a different view, the page reloads unexpectedly. This problem seems to occur only with the route containing the modal component. Removing the modal solves the issue. Is there something I'm overlooking? Should the modal component be placed outside of the layout?

Here is a snippet from Layout.vue:

<template>
    <div>
        <Modal v-if="this.$route.name === 'Item'" />
        <Navbar />
        <transition-group name="jumbo">
            <Jumbotron :key="1" v-if="this.$route.path === '/'" />
            <SecondaryJumbotron :key="2" v-if="this.$route.path !== '/'" />
        </transition-group>
        <transition appear name="page">
            <router-view></router-view>
        </transition>
        <SideItems
            v-if="this.$route.path !== '/' && this.$route.name !== 'Item'"
        />
        <Footer />
    </div>
</template>

<script>
import Navbar from "./components/Navbar";
//other imports...
import Modal from "./components/Modal";

export default {
    name: "app",

    components: {
        Modal,
        //other components
        SideItems
    }
};
</script>

List of routes:

const routes = [
    {
        name: "Home",
        path: "/",
        component: index,
        meta: {
            title: "Home" + appName,
        }
    },
    {
        name: "Signup",
        path: "/signup",
        component: signup,
        meta: {
            title: "Signup" + appName,
        }
    },
    //other routes...
    {
        name: "Item",
        path: "/item/:id",
        component: item,
        meta: {
            title: "Item" + appName,
        }
    },
];

Snippet from Modal.vue:

<template>
    <div class="modal" id="item-modal" @click="modalHide">
        <div class="modal-item-image" @click="modalHide">
            <img :src="getMainImage" @click="modalHide" />
        </div>
    </div>
</template>

<script>
import { mapGetters } from "vuex";

export default {
    computed: {
        ...mapGetters(["getMainImage"])
    },

    methods: {
        modalHide() {
            document.getElementById("item-modal").style.animation =
                "opacity-out 0.4s cubic-bezier(0.215, 0.61, 0.355, 1) forwards";
            document.getElementById("item-modal").style.pointerEvents = "none";
        }
    }
};
</script>

Answer №1

After some investigation, I discovered that the placement of the component above the navbar was leading to the issue, although the reason remains unclear.

To resolve this, I relocated the component below the navbar and adjusted the margin-top to -140px, successfully resolving the problem.

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

Can we selectively execute certain tests in Cypress using support/index.js?

I need to selectively run certain tests from a pool of 50 test files located in the integration folder. Specifically, I only want 10 of them to execute. In an attempt to achieve this, I am trying to configure the selection process within the support/index. ...

Having trouble with submitting a form using Laravel, Vue, and Inertia?

I encountered an issue with Laravel Vue Inertia while using Bazar from GitHub. Everything was working fine until I attempted to create a new page called Voucher, which was essentially a replica of the Categories page. However, when I tried to create a new ...

Using jQuery to open a new window and automatically inputting a value into the textbox

I've been struggling with a basic concept for hours now and all my Google searches have turned up empty. I'm working with an HTML file that contains a div which, when clicked, should open a new window. In this new window, the input box should dis ...

Determine the current directory being called in Grunt, without confusing it with the directory of the gruntfile

If Grunt is installed in a folder called /foo, but my current directory is /foo/bar/baz, and I execute "grunt sometask" from within my current directory, how can I programmatically determine the path of the current directory where Grunt was called? In othe ...

Refreshing the page causes the Angular/Ionic Singleton instance to be destroyed

I have a TypeScript singleton class that is responsible for storing the login credentials of a user. When I set these credentials on the login page and navigate to the next page using Angular Router.navigate (without passing any parameters), everything wor ...

Create a router link in Vue using the command "Vue

I have a Vue application that displays videos. I am looking to automatically generate a random router link every time I click on: <router-link to="/video/this_value_to_be_random">Random video</router-link> Within the component: <vue-vide ...

What is the process for adding new data to a data source without overwriting existing information?

I need assistance with a react native app I am developing. I am currently facing an issue where the data received from a fetch request needs to be displayed in a list view. However, each time new data is fetched, it overwrites the previously received data ...

Unable to load models in face-api.js even though attempting to infer the models

Currently, I am working on developing an application for face detection. However, I am encountering an error stating "SsdMobilenetv1 - load model before inference" despite loading the models. The Front End HTML File is being sent from the server, ...

Cross-platform mobile browsers typically have scrollbars in their scrollable divs

I have successfully implemented scrollable div's on a page designed for tablets running Android 3.2+, BlackBerry Playbook, and iOS5+ (except iPad 1). However, I would like to add scrollbars to improve the user experience. For iOS5, I can use the suppo ...

The topic at hand pertains to a specific exercise featured in the well-known book Eloquent JavaScript

In this exercise, the final step is to create a recursive function that takes a joined list and an index as parameters. The function's purpose is to find the value in the object within the list at the specified index. The code I have written seems to ...

"Transforming a static navbar to a fixed position causes the page to jump

Having some difficulty figuring this out. I'm working on a bootstrap navbar that transitions from static to fixed when the user scrolls past the logo at the top. Everything seems to be working fine, except for when the navbar reaches the top, it sudde ...

Initiating Ajax to trigger the body's onLoad event

Whenever I use an ajax call to load a div, the entire page refreshes. It seems that the 'body onload=init()' event is triggered on ajax response causing all the initialization to repeat, which is not desired. Is there a way to only load the div t ...

The Date Picker pops up automatically upon opening the page but this feature is only available on IE10

There seems to be an issue with the date picker opening automatically on IE10, while it works fine in Firefox where it only appears when you click on the associated text box. Does anyone have insight into why this might be happening specifically in IE10? ...

Error in Vue.js: Trying to access properties of an undefined object

My understanding of vue.js is limited, but based on what I know, this code should work. However, when attempting to access the variable in the data property, it seems unable to locate it. data: function() { return { id: 0, clients: [] ...

The fusion of Combining Forms, JSON, AJAX, PHP, and Google graphs

I'm completely new to integrating JScript, Ajax, and Google Graphs. Although I've managed to get each of them working separately, combining them has proven to be quite challenging. Google Graph Part of my code (Form is inactive here): <html& ...

Using MeanJS to assign a Mongoose object reference to an array in Angular

Having an issue with MeanJS and using the $update function of the $resource service in Angular provided by MeanJS. Here is a basic outline of my problem: Mongoose schema: var mongoose = require('mongoose'), Schema = mongoose.Schema; var Lotion ...

What is the best way to add a picture using React and Next.js?

Being a novice in React and Next, I recently embarked on a project that involves uploading a profile picture. However, every time I try to upload an image, an error pops up. Error: The src prop (http://localhost:3333/files/ SOME IMAGE.jpg) is invalid on n ...

Focus on programmatically generated elements by utilizing refs

I need to set focus on the Input within a custom component by creating dynamic refs. This is how I'm currently rendering the elements: const createRefForCountRow = denom => { this[`${denom.id}-ref`] = React.createRef(); return ( <Count ...

If I don't utilize dependency injection in Angular, it prompts me for arguments

Attempting to implement a service like this but encountering some issues translateService = new TranslateService(); An error message pops up stating that there are 9 missing arguments. However, when I modify it to look like this constructor(private trans ...

Activate a button on-the-fly

When the page loads, I have an empty array. Since there are no values stored in this array, I disabled the button using ng-disabled="array1.length==0". Now, on the page that opens up, there are four drop downs present. My goal is to enable the button once ...