Revise the modal window

I need help with switching between two modal windows for registration and login. How can I make the modal window change when the "Sign Up" button is clicked?

Here is the link to my project: https://jsfiddle.net/Alienwave/0kqj7tr1/4/

Vue.component('signup', {
    template: '#signup-template'
})

Vue.component('login', {
    template: '#login-template',
    data() {
        return {
            loginInput: '',
            passwordInput: ''
        }
    },

    methods: {
        sendRequest(e) {
                    //code not here
        },

        changeModal() {
                        // THIS!!
        }
    }
});

new Vue({
    el: "#app",
    data() {
        return {
        showLogin: true,
            showSignup: false
        }
        }
        });

Below is the login template snippet:

<template id="login-template">
        <transition name="modal">
            <div class="login-mask">
                <div class="login-wrapper">
                    <div class="login-container">
                        <div class="login-footer">
                            <slot name="footer">
                                <div class="change-mode">
                                    <button class="change-mode-reg" @click="">Sign up</button> <!-- THIS BUTTON SHOULD CHANGE MODAL! -->
                                </div>
                            </slot>
                        </div>
                    </div>
                </div>
            </div>
        </transition>
    </template>

The register template follows a similar structure. This is just an excerpt from my code.

Answer №1

Vue's custom events can be utilized effectively in this scenario. Below is the suggested code update:

#login-template

...

<div class="login-footer">
  <slot name="footer">
    <div class="change-mode">
      <button class="change-mode-reg" @click="changeModal">Sign up</button>
      <div class="change-mode-line"></div>
    </div>
  </slot>
</div>

...

login component

Vue.component('login', {
  template: '#login-template',
  data() {
    return {
      loginInput: '',
      passwordInput: ''
    }
  },
  methods: {
    sendRequest(e) {
      //code not here
    },
    changeModal() {
      this.$emit('change');
    }
  }
});

#app

<div id="app">
  <login v-if="showLogin" @close="showLogin = false" @change="changeModal"></login>
  <signup v-if="showSignup" @close="showSignup = false"></signup>
</div>

To view the updated code, check out this revised fiddle.

(Please note: although the modal switching issue is resolved, there may be other underlying problems present in your current implementation.)

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

Add new content to an existing JSON file in a Node.js environment

I'm encountering an issue while attempting to insert new text into an existing JSON file. I've experimented with writeFileSync and appendFileSync methods, however the added text does not maintain JSON formatting even when utilizing JSON.stringify ...

Can you recommend a straightforward method in Vue.js for validating the format of user input?

Here is how I have implemented an email sending feature in Vue.js: <template> <button @click="sendMail(); $emit('close')">Send</button> </template> <script> methods: { sendMail () { axios ...

Retrieve specific information from a JSON file and save it in an array using Node.js/JavaScript

My goal is to extract all log details from a JSON object, but the issue is that the key for each user is constantly changing. let userJsonObject = { "user_1":{ "id":"user_1", "log":"de-data", ...

Deciphering Google location data using JavaScript

It appears that this code is not functioning properly for unknown reasons let url = "https://maps.googleapis.com/maps/api/place/search/json?"; url += "location="+lat+","+lng+"&"; url += "radius=500&"; url += "types=&"; url += "name=&"; url ...

Issue with Observable binding, not receiving all child property values in View

When viewing my knockout bound view, I noticed that not all values are being displayed. Here is the script file I am using: var ViewModel = function () { var self = this; self.games = ko.observableArray(); self.error = ko.observable(); se ...

What is the best way to specify a function parameter as a Function type in TypeScript?

I'm currently delving into the world of TypeScript and I am unsure about how to specify a function parameter as a function type. For instance, in this piece of code, I am passing a setState function through props to a child component. const SelectCity ...

The troubleshooting of debugging javascript remotely on IntelliJ with the JetBrains Chrome extension is proving to be unsuccessful

I've been attempting to set up a debugger for some JavaScript files that I'm working on in IntelliJ (version 2020.1.4). Following the guidelines provided here Debug with JetBrains Chrome extension, I believe I have successfully completed all the ...

Is there a way to retrieve the information from the v-text-field without using the v-model directive?

<div v-for="i in parseInt(questionCount)" :key="i"> <v-layout> <v-flex xs6 offset-3 mt-15" > <label for=""> Enter question number {{index}}:</label> <v-text-fi ...

Utilizing jQuery to place an element beside another and maintain its position

I need ElementA to be positioned next to ElementB as shown in this example. The key difference is that I want ElementA to move along with ElementB if the latter is relocated. Is there a way to keep a specific element fixed to another one? Re-calculating ...

Subdomain for an Ajax request

Can we use ajax requests to extract data from and fetch information from pages like ? It appears that JavaScript still does not permit subdomain requests. ...

Error in Express JS: Attempting to access properties of an undefined variable (reading '0'). Issue with SQL query

Struggling to insert something in my database and then access it directly after. Due to the asynchronous nature of node.js, my plan doesn't seem to work out. However, I am confident that there is a solution to make this happen. Here's the code sn ...

Implementing pagination for images offers a user-friendly browsing experience

My friend and I are in the process of creating a website that displays images from two directories in chronological order. The image name serves as a timestamp, and we generate a JSON object using PHP with the code below: <?php $files = array(); $dir ...

Encountered difficulties while attempting to use keyboard input and received a null value when attempting to retrieve a data-* attribute using Python and Selenium

Encountered an issue with keyboard interaction and finding a null value for the data-* attribute during automated login attempts on Gmail using Python and Selenium While attempting to automatically log in to Gmail using Python and Selenium, I successfully ...

Stop Antd Modal from automatically scrolling to the top

At the moment, I'm utilizing Ant Design (v4.22.8) and Next.js (v12.3.4) in my project. One issue I've encountered is with a Modal component that activates when a button is clicked. Instead of overlaying the current content on the screen, the moda ...

What is the process for generating an array of objects using two separate arrays?

Is there a way to efficiently merge two arrays of varying lengths, with the number of items in each array being dynamically determined? I want to combine these arrays to create finalArray as the output. How can this be achieved? My goal is to append each ...

If the input is marked as checked, apply a class to the corresponding HTML element

I need to manipulate the .form-group class by adding it if the nearest hotelObj element is checked, and removing it when hotelObj is unchecked. Instead of using addClass(), I prefer to utilize css(). $(".form-group").click(function() { if ($(this).ch ...

Divide the string into several segments according to its position value

Here is a piece of text that I would like to divide into multiple sections, determined by the offset and length. If you have any questions or comments and would like to get in touch with ABC, please go to our customer support page. Below is a function ...

The Page is Not Able to Scroll

Occasionally, my app stops allowing scrolling of the entire page length. Everything will be working fine for a while, but then out of nowhere, the page suddenly becomes un-scrollable and you can only interact with the section currently visible on the scree ...

Unique rewritten text: "Displaying a single Fancybox popup during

My website has a fancybox popup that appears when the page loads. I want the popup to only appear once, so if a user navigates away from the page and then comes back, the popup should not show again. I've heard that I can use a cookie plugin like ht ...

Expanding the MatBottomSheet's Width: A Guide

The CSS provided above is specifically for increasing the height of an element, but not its width: .mat-bottom-sheet-container { min-height: 100vh; min-width: 100vw; margin-top: 80px; } Does anyone have a solution for expanding the width of MatBott ...