Hiding Modal Box Upon User Login: A Step-by-Step Guide

After a user clicks the login button in my navigation, a modal box pops up. However, once the user logs in, the modal box does not disappear.

How can I hide or remove the modal box when users click on the login button?

This code snippet is from Home.vue:


    <div id="myModal1" class="modal  centered-modal" role="dialog">
      <div class="modal-dialog login_dialog">
        <div class="modal-content">
          <button type="button" class="close" data-dismiss="modal">
            <i class="fa_icon form_close"></i>
          </button>
          <div class="modal-body">
            <div class="ms_register_img">
              <img src="images/register_img.png" alt="" class="img-fluid" />
            </div>
            <div class="ms_register_form">
              <h2>Log In</h2>
              <form @submit.prevent="submit">
                <div class="form-group">
                  <input type="email" placeholder="Enter Your Email" class="form-control" v-model="form.email">
                  <span class="form_icon">
                  <i class="fa_icon form-envelope" aria-hidden="true"></i>
                  </span>
                </div>
                <div class="form-group">
                  <input type="password" placeholder="Enter Your Password" class="form-control" v-model="form.password">
                  <span class="form_icon">
                  <i class="fa_icon form-lock" aria-hidden="true"></i>
                  </span>
                </div>
                <div class="form-group">
                  <button class="reg_ms_btn" type="submit">Log In</button>
                </div>
              </form>   
              <div class="remember_checkbox">
                <label>Keep me signed in
                  <input type="checkbox">
                  <span class="checkmark"></span>
                </label>
              </div>

              <div class="popup_forgot">>
                <a href="#">Forgot Password?</a>
              </div>
              <p>Don't Have An Account? <a href="#myModal" data-toggle="modal" class="ms_modal1 hideCurrentModel">Register here</a></p>
            </div>
          </div>
        </div>
      </div>
    </div>

Answer №1

Include a conditional statement like v-if="userLoggedIn" or v-if="user.userName != 'guest'".

It is assumed here that users who are not logged in have the username 'guest'.

<div v-if="userLoggedIn" id="myModal1" class="modal  centered-modal" role="dialog">

I trust this information proves useful.

Answer №2

To ensure the modal closes when the login button is clicked, you must include a toggle and target property in the code. Update the login div as follows:

<div class="form-group" data-toggle="collapse" data-target="myModal1">
  <buttonclas="reg_ms_btn" type="submit"> Log In</button>
</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

What is the best way to showcase images using Vue.js?

For my Vue project, I am encountering issues with the image paths not working properly. Despite trying different variations, such as: <figure class="workout-image"> <img :src= "images.bicep" width= "200px" ...

Utilize a personalized useFetch hook in React.js to transmit a POST request and obtain a response

I recently came across a great resource on this website that provided the logic for a useFetch hook. My goal is simple - I want to send a post request and then map the response into a specific type. While this seems like it should be straightforward, I&apo ...

Ways to invoke a class method by clicking on it

My initialization function is defined as follows: init: function() { $("#editRow").click(function() { <code> } $(".removeRow").click(function() { <code> } } I am trying to find a way to call the class method removeRow directly in the onc ...

Error encountered in TypeScript's Map class

When working with TypeScript, I keep encountering an error message that reads "cannot find name Map." var myMap = new Map(); var keyString = "a string", keyObj = {}, keyFunc = function () {}; // assigning values to keys myMap.set(keyString, "val ...

What are the steps to incorporate swipe functionality into my component?

I've created a carousel using React-slideshow-image, but the issue is that it doesn't support swiping on mobile devices. I would like to implement swipe functionality myself, but I'm not sure how to go about it. Can anyone provide guidance ...

Utilizing the power of JavaScript within HTML to remove elements upon being clicked

Seeking help again for the page I'm building where I keep encountering errors. As a beginner, I find myself puzzled and in need of assistance. My task is to utilize a for loop to iterate over the images and attach an event listener to each one so that ...

Is there a way for me to generate a tab that shows content when hovered over?

Is it possible to create a tab that displays a vertical list of redirections when the mouse hovers over it, and hides when the mouse is moved away? This seems like a challenging task. Can someone guide me on how to achieve this, especially if it involves ...

The basic node API request is not showing any information

There is a request in my server.js file var Post = require('./../models/post'); //GET ALL POSTS app.get('/api/posts', function (req, res) { Post.getPosts(function (err, posts) { if(err) { throw err; } ...

NodeJS is facing a severe challenge in properly rendering HTML and its accompanying CSS code, causing a major

Once upon a time, I built a beautiful website while practicing HTML, CSS, and JS. It had multiple web pages and used Express for the backend. Unfortunately, I lost all the files associated with it and took a break from web programming for some time. Now, w ...

What could be causing the issue with clicking on children of jstree not working?

I am encountering an issue with jstree. Once the data is changed, the click event does not work for every subsequent click. I find that I need to refresh the page in order to make it work. Here is a link to the jsfiddle: http://jsfiddle.net/2Jg3B/2121/ I ...

Checkbox Selection - Modify Prompt to "Kindly mark this box to continue"

I have created a multi-select checkbox form, and I've added some JavaScript to ensure that the visitor selects at least one option <div class="form-group options"> <label class="control-label col-md-4" for="optiontext">Specify an option&l ...

When calling UIComponent.getRouterFor, a TypeScript error is displayed indicating the unsafe return of a value typed as 'any'

I have recently integrated TypeScript into my SAPUI5 project and am encountering issues with the ESLint messages related to types. Consider this simple example: In this snippet of code, I am getting an error message saying "Unsafe return of an any typed ...

Troubleshooting [Vue Router warning]: Ignoring invalid parameter(s) "id" during navigation

Incorporating VueJS 3.3 along with Vue Router v4, my route structure is as follows: https://i.stack.imgur.com/ExZ9N.jpg Despite navigating properly to the intended URL http://localhost:5173/koin/document-sets/177/comments, Vue continuously throws an erro ...

How to efficiently eliminate duplicates from an array list using React framework

Keeping the array name constant while duplicating and repeating this process only clutters the list. Appreciate your help. setListItems(contents.data); console.log(contents.data); ...

Adding an item to a JSON array in Angular

I'm having trouble adding a new item to the roleList JSON array. I've tried using push/concat, but it doesn't seem to update the roleList array. Any suggestions on how to resolve this? // The javascript : function RoleListCtrl($scope) { ...

Angular connecting to the count of filtered items

Here's the array I'm working with: [ { type: "hhh", items: [ { "name": "EGFR", "type": "a", "selected": true } ] }, { type: "aaa", items: [ { ...

Delay loading of external JavaScript with data attributes

Exploring options for lazy loading this code snippet: <script async src="https://comments.app/js/widget.js?3" data-comments-app-website="TvibSQx_" data-limit="5" data-color="29B127" data-dislikes="1" dat ...

Issue when Updating Component State: React child cannot be an object

I'm currently in the process of familiarizing myself with React and how to manage component state. My goal is to build a component, set up the initial state using a constructor, make a GET request to the server to fetch an array of objects, and then ...

Tips for incorporating conditional statements within return statements in functional components in React JS

I need to display the login page if the user is not logged in, otherwise show the forbidden 403 page. Since I'm using a functional component, I can't use render(). return forbidden === false ? ( <> <Container maxWidth="x ...

Utilizing a Static Image Path Prop in React JS: A Step-by-Step Guide

My Main Component import React from "react"; import TopModal from "./components/topModal"; // Passing productImage to the Child Component import productImage from "../../../../../../assets/images/juices.jpg"; import { makeS ...