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

Translate a jQuery ajax request utilizing jQuery().serialize into plain JavaScript

Currently, I've been in the process of converting a jQuery script into vanilla JavaScript to completely eliminate the need for jQuery. The main functionality of the code includes: Upon clicking a button on the front end, an ajax request is sent, upda ...

Implementing the Upload Feature using AngularJS

Currently, I'm facing a challenge in implementing an upload button on my webpage using AngularJS and Bootstrap. Specifically, I am having trouble assigning the (upload) function to that button in AngularJS. The goal is for the button to enable users t ...

Customize the CSS for MaterialUI's TablePagination's MenuItem

Having trouble figuring out how to override CSS for the child component MenuItem within TablePagination? Check out this link for more information: https://github.com/mui-org/material-ui/blob/master/packages/material-ui/src/TablePagination/TablePagination.j ...

Unable to retrieve the content of Material UI Textfield

I'm new to React and I need help with my login page that uses Firebase authentication. I have an input field to capture the user's contact information for validation, but I'm having trouble retrieving this data. I've tried various solut ...

Transforming color images into black and white using JavaScript

     I have implemented this code to convert colored images to grayscale. function applyGrayscaleEffect() {         var imageData = contextSrc.getImageData(0, 0, width, height);         var data = imageData.data;         var p1 = 0.99;   ...

What is the comparable javascript code for the <script src="something1.json"></script> tag?

Within my HTML code, I currently have the following line to read a JSON file: <script src="something1.json"></script> Inside this JSON file, there is a structure like so: var varName = { .... } This method of definition naturally sets up ...

Encountering Err_Connection_Refused while working with MVC WebAPI 2 and AngularJS

Seeking guidance on WebAPI, AngularJS, and .NET Authentication, I am currently following a tutorial mentioned HERE. The tutorial is brief (~under 10 mins), but I encountered an error stating Failed to load resource: net::ERR_CONNECTION_REFUSED. Typically, ...

Vue.js is having trouble locating images

I am currently using Vue-CLI with the latest version of Vue (3.9.3), but I am facing an issue where Vue cannot locate my images. Below are some screenshots for reference. Why are the images not showing up? First image (Structure) Second image (template) ...

Having trouble getting Handsontable to scroll smoothly in Chrome?

I'm currently facing an issue with handsontable specifically on Chrome. The problem is that although the table itself is scrollable, the values and row headings within the table do not update as they should. You can see the issue illustrated in the im ...

When it comes to utilizing jQuery for the mobile view, how many jQuery libraries are recommended for optimal performance?

I'm currently constructing a website using ROR, and for the mobile view, I've implemented the mobile_fu gem. The designer provided me with a design for the mobile view that includes various jQuery sliders, players, image sliders, drop-down menus ...

Vue.js router-link component not being created

When attempting to generate a link to a view using <router-link>, I am encountering issues with it not creating the proper link. In a TypeScript component: <div id="nav"> <ul class="menu-list"> [...] &l ...

Retrieving the output of a parent computed method in VueJS, using a child component

I am facing difficulties in passing the dynamically changing value of a computed method to my child component. I am creating a button component with different save states, but the button always remains stuck on one state and does not update according to th ...

Inertiajs - Redirecting Asynchronously

I have a quick inquiry regarding inertia and asynchronous rendering. It seems that when I delete a database entry and immediately connect to a new navigation link (using Inertia.onStart) which redirects me to another page, the changes are not reflected on ...

Track and monitor data modifications in Vue.js

I recently incorporated a Bootstrap Vue Table into my application and wanted to monitor user activity as they navigate through the pages using the pagination feature. Here is where you can find more information on the Bootstrap Vue Table To achieve this, ...

What are the best methods for preserving paint color when changing wheel styles, and vice versa?

I posted this query about a year ago, but I did not have a fiddle prepared at that time and my question was not as well articulated as it could have been. Despite that, many people came forward to offer their help, and I am truly grateful for that. This ti ...

Several jQuery ajax requests seem to be failing due to errors in previous calls

I am experiencing an issue with my website's login form that utilizes ajax to send the login information to php. After successfully logging in, users have the ability to log out and then return to the login page again. However, I am facing a problem w ...

How can I implement Before() and After() hooks within a hooks.js file for a Selenium and JavaScript project?

Within my Selenium JS / Cucumber framework, I have incorporated Before() & After() functions to handle the setup and tear down of my webdriver. To manage these functions, I decided to organize them in my customSteps.js file alongside other cucumber st ...

Leveraging unplugin-vue-components within a monorepository

Situation In my monorepo (Using Turborepo), I have multiple Vue3 apps and packages. Each app is built with Vite and uses unplugin-vue-components for importing components automatically from the specific app. Additionally, I need to include components from ...

Implementing event listeners with Angular UI-Router

Currently, I am working with Angular 1.4.5 and Angular Ui Router. I am facing an issue where I am trying to utilize addEventListener to execute a function when a text field is blurred. The challenge I am encountering is that during the load state, the elem ...

I am experiencing an issue where my JSON array is only returning the last element. Any suggestions on how to

I am facing an issue with my JSON array and Ajax code. Here is the snippet of my code where I upload an Excel file, convert it to JSON, then save it as a string in my database: function exportExcelToTable() { $('#upload-excel-convert').chang ...