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

What is the sequence of the middlewares for error handling and handling of 404 errors?

The express.js website has confused me with contradictory statements regarding error-handling middleware. According to one page, you should define error-handling middleware last, after other app.use() and routes calls. However, another page states that you ...

Is it time to execute a mocha test?

Good day, I am currently exploring the world of software testing and recently installed Mocha. However, I seem to be encountering an issue with running a basic test that involves comparing two numbers. Can someone please guide me on why this is happening a ...

Tips for altering an element's style attribute using ERB and JQuery while including a % symbol within the value

I'm attempting to adjust the style="width: 5%" attribute of a span using Jquery and AJAX. This width needs to be specified in percentage as it represents a progress bar. Here is my code snippet from html.erb: <div class="progress success round" ...

Issue with updating robot's direction using string in Javascript not resolving

Javascript Developing a simple game where a robot moves on a 5x5 board based on user input commands 'L' (move left), 'R' (move right), and 'F' (move forward) from a starting position while facing North (N). Clicking the Move ...

Discover the way to retrieve PHP SESSION variable within JavaScript

I'm currently working on developing a platform for image uploads. As part of this project, I assign a unique identifier to each user upon login using $_SESSION['id'] in PHP. Now, I am looking for a way to verify if the $_SESSION['id&apo ...

Creating a script to open multiple URLs in HTML and JavaScript

Currently, I am working on creating a multiple URL opener using HTML and JavaScript. However, I have encountered an issue where HTTP links are opening fine but HTTPS links are not. Can someone provide assistance with this problem? Below is the code snippet ...

Having trouble accessing object properties fetched via API, receiving the error message "TypeError: Cannot read property '' of undefined" in Next.js with JavaScript

Encountering a unique issue specific to NextJs. Fetching data from an API using a custom hook and receiving an array of objects as the result. Successfully logging the entire result (array of objects). const myMovieGenreObjects = useFetchNavBarCategories( ...

Creating a CSS full-width navigation menu

Recently, I came across a menu code on the web that seemed great. However, I wanted to make my menu responsive and full width. Since I am new to CSS and HTML, adjusting the menu code has been a bit of a challenge for me. .menu, .menu ul { list-style: ...

Saving form data with a tinymce textarea, radio button, and checkbox to the database

My form contains multiple textarea fields, radio buttons, checkboxes, and a select input. Initially, I was able to submit the form using PHP without any issues. However, when I integrated TinyMCE with one of the textareas, I had to introduce JavaScript to ...

What could be causing this jQuery color picker to malfunction when used inside a Bootstrap modal?

Currently, I am utilizing the fantastic jQuery color picker provided by Although it functions as expected in "normal" scenarios, I have encountered an issue where the picker fails to display when the input parent element is nested within a Bootstrap 3 mod ...

AngularJS 2: Updating variable in parent component using Router

My current app.component looks like the following: import { Component, Input } from '@angular/core'; import {AuthTokenService} from './auth-token.service'; @Component({ selector: 'app-root', templateUrl: './app ...

Issue with Ant Design Vue3: Data in Editable Table Not Updating

I am currently facing an issue with the table component from ant design. I cannot figure out why it is not functioning as expected. You can find the reference link here: The source code related to the editable table in ant design: <template> < ...

Leap over in a similar fashion to the provided demonstration

In my attempt to create a unique project, I have created this CodePen example. The goal is to have one ball on the circle that remains in a fixed position, while another rotating main ball must avoid touching it at all costs. Points are awarded for success ...

Exploring uncharted territory with the Navigator component in React Native

I am experiencing an issue with undefined navigator when using React Native MessageTabs: _onPressItem = (item) => { const { navigate } = this.props.navigation; //console.log(JSON.stringify(item)); navigate('SingleConversation', {id ...

The validation feature in 1000hz Bootstrap seems to be malfunctioning

I've been working on implementing validation using the 1000hz bootstrap validation plugin. Most things are going smoothly, but I'm encountering two issues: 1). The data-match attribute doesn't seem to be working even when I enter the same p ...

How can you incorporate AJAX to add a paragraph element to your HTML document?

I have encountered an issue with two files in my project. The first file is an HTML document, while the second file is a PHP file called ajax_access_database.php. Originally, I intended for the PHP file to access a database, but complications arose, leadin ...

Creating a custom route that is specific to a single ejs file

I'm trying to set up a URL like localhost:3000/hh234due with a unique ID that routes to a specific page. However, my current implementation is conflicting with other routes. How can I make the /:id route unique to one view? module.exports = fun ...

Error message indicating that `vue-loader` could not be located when attempting to run `npm run

I keep encountering an issue when trying to run npm run dev. I'm getting the following error and have no idea how to resolve it. I've tried reinstalling Node.js to the latest version and reinstalling all packages via the command line: [webpack-cl ...

The collaboration of Node.js and React.js on a single server

Separate ports are used for Node and React, but API requests from the React app can be proxied to the Node URL. I have opted not to implement server-side rendering for React in order to serve the React app. Instead, I build the React app each time there i ...

Tips on making an array readable by JavaScript using Jinja2 and Google App Engine

I'm currently facing an issue with transferring an array from a server to a web page through Jinja2 in Google App Engine. Despite my efforts, I'm struggling to make the array readable by my jQuery code. This is all new to me as it's my first ...