Having trouble with Vue.js on one of my CSHTML pages

As I work on developing a website using NET Core 3 and VueJS, one of the key areas is the login page:

@page
@model project.Web.Pages.Accounts.LoginModel
@{
    ViewData["Title"] = "User Login - ";
    Layout = "../Shared/_Layout";
}

<!-- add class=modal-->
<div id="app">

<div id="modal">
    <div class="modal-background"></div>
    <div class="modal-content">
        <div class="columns is-centered">
            <div class="column is-12">
                <div class="card auth-card">
                    <div class="card-content">
                        <div class="login-form is-grouped-centered">
                            <form method="post">
                                <p class="login-form__title subtitle">Sign In or Register</p>
                                <div asp-validation-summary="All" class="has-text-danger"></div>
                                <div class="login-form__field field">
                                    <div class="login-form__email-group form-row">
                                        <label class="login-form__email-label" asp-for="Input.Email">My Email</label>
                                        <input class="login-form__input control input" asp-for="Input.Email" id="email-input" placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="83e9ecebedade7ece6c3e6fbe2eef3efe6ade0ecee">[email protected]</a>" required maxlength="255" />
                                        <span asp-validation-for="Input.Email" class="has-text-danger"></span>
                                    </div>
                                </div>
                                <p class="login-form__title subtitle">Are you an existing customer?</p>
                                <div class="login-form__radio-group">
                                    <input type="radio" class="login-form__radio-group-radio radio" @@click="setPasswordDisabled(true)" name="new_account" value="1" id="signin_new_customer">
                                    <label for="signin_new_customer">No, sign me up.</label>
                                </div>
                                <div class="login-form__field login-form__radio-group">
                                    <input type="radio" class="login-form__radio-group-radio radio" @@click="setPasswordDisabled(false)" name="new_account" value="0" id="signin_existing_customer" checked>
                                    <label for="signin_existing_customer">Yes, my password is</label>
                                    <div class="login-form__radio-group">
                                        <input class="login-form__input control input" asp-for="Input.Password" id="auth-password" required />
                                        <span asp-validation-for="Input.Password" class="has-text-danger"></span>
                                    </div>
                                </div>
                                <div class="field has-text-right">
                                    <a href="#">Forgotten your password?</a>
                                </div>
                                <div class="login-form__submit">
                                    <input v-if="!isNewAccount" class="login-form__submit-button button is-success" type="submit" name="name" value="Sign In" />
                                    <a v-if="isNewAccount" class="login-form__submit-button button is-success" asp-page="/Accounts/Register">Sign Up</a>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <button class="modal-close is-large" aria-label="close" @@click="toggleModal()"></button>
</div>
</div>

@section scripts {
    <script src="~/js/login.js"></script>
}

Additionally, within the 'login.js' script file, there are functions to manage certain actions related to account creation, but upon inspection in the network tab, it appears that these functions are not being executed. Despite loading the 'Login.js' file successfully, the expected functionality does not trigger as intended, leaving me puzzled.

I have attempted enclosing the markup from 'Login.cshtml' into a div with an ID of "app," yet this has not resolved the issue. There are no error messages or warnings displayed in the console, adding to the mystery surrounding this behavior. The property 'isNewAccount' seems visible in the Vue DevTools, however, its value remains unchanged even when interacting with the radio buttons. Furthermore, the display logic based on 'isNewAccount' does not reflect accurately within the Login Page. This inconsistency is frustrating, especially considering the additional checks included.

If anyone has encountered a similar issue before or can offer insights into troubleshooting steps, I would greatly appreciate any assistance.

https://i.sstatic.net/t5HZS.png

Answer №1

It took me quite some time to figure out the root cause of the problem - turns out I had multiple instances of Vue app running simultaneously, when only one instance is permitted. Once I removed the

, the issue was resolved.

Answer №2

Implementing v-model allows you to easily update your data

<div class="login-form__radio-group">
    <input type="checkbox" class="login-form__radio-group-radio radio" v-model:"isNewAccount" name="new_account" id="signin_new_customer">
    <label for="signin_new_customer">No, sign me up.</label>
</div>

Consider using type="checkbox" over type="radio"

Add a name="" or id="" attribute to specify styles for your elements. This will provide clarity and organization.

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

Is it possible to transfer data from javascript to php through ajax?

I am attempting to extract the data speedMbps from my JavaScript code using Ajax to send the data to my PHP script, but unfortunately, I am not receiving any output. My experience with Ajax is limited to implementing auto-completion feature. <script sr ...

Ways to retrieve a service variable within a delegated function (callback)

I am currently using a service that has a variable which needs to be updated by the service itself. However, I am facing an issue where I cannot access the variable in anonymous or delegated functions. (function() { 'use strict'; angular ...

Angular's $routeProvider fails to navigate

I'm facing an issue with my Angular JS application where the $routeProvider doesn't load the template in the ng-view section. I have set up <html data-ng-app="myApp"> and <section data-ng-view></section. The template doesn't ...

`"Error code 404 - Slash command not found" encountered in discord.js version 12.5.3 while attempting to delete slash commands. This issue has been resolved."`

I am currently in the process of revamping a discord.js music bot that I created some time ago. However, I have encountered an issue where I need to delete my slash commands in order to start fresh. Whenever I attempt to use the client.api.application(clie ...

A different approach to fixing the error "Uncaught (in promise) TypeError: fs.writeFile is not a function" in TensorFlow.js when running on Chrome

I've been attempting to export a variable in the TensorFlow posenet model while it's running in the Chrome browser using the code snippet below. After going through various discussions, I discovered that exporting a variable with fswritefile in t ...

The v-tooltip feature fails to display the component that is situated directly beneath it

I am attempting to incorporate v-tooltip into my project by following the example provided in their documentation, but unfortunately I am encountering difficulties. When I try to replicate the example, I am presented with the following error: [Vue warn]: ...

What causes my local storage to be cleared whenever I refresh the page in React with Redux?

What causes my local storage to reset to empty whenever I refresh the page? I am attempting to save data to local storage that is also passed to my redux state, but I am unable to do so. const retrieveLocalStorage = () => { const oldExpenses = JSON ...

The text does not change in the input field even with the .value method

I'm encountering an issue where I want to use .value to set the text of an input field. However, after setting the value of the input field, the text disappears when clicked on. I would like to find a solution where the text does not disappear upon cl ...

Utilize the ng-controller directive with unique aliases across various sections of HTML code

I'm facing an issue with my ng-controllers when multiple controllers are used on the same page. For instance, I have one controller in the page header, another in a different section of the same page, and one in the content of the page. However, all o ...

After the JQuery refreshes the DIV, my JavaScript function ceases to function properly

I'm trying to create a search bar that uses jQuery to search for data, and then displays the results in a 'div' without refreshing the page. However, when I clear the search bar, the old div doesn't reset properly. Furthermore, after th ...

A more efficient approach to creating a personalized design

After realizing the original question was unclear and wouldn't solve my problem, I have decided to edit it and create a new one. For my project, I require a customized layout where users can move, resize, add, or remove each box according to their pr ...

Updating a value within destructuring and a loop: A step-by-step guide

My Goal: I aim to modify a value in an object that is part of an array element. Take a look at the code snippet below for a clearer understanding. An issue arises when I update the object's value through reference instead of creating a new copy, cau ...

Displaying a JSON response on an HTML webpage

JSON object: {"id":75,"year":2011,"make":"Aston Martin","model":"V12 Vanquish"} jQuery: function post() { $("form").on("ajax:success", function(e, data, status, xhr) { var json = JSON.parse(xhr.responseText); $.each(json, function(k, v) { ...

Javascript phone number verification- eliminating error messages

Objective: To ensure that phone numbers are entered in the correct format (e.g. 208-111-1111) and display an error message if the format is incorrect. How can we make sure the error message disappears once the user re-enters the correct format? JS phoneN ...

What steps can I take to perform unit testing on a custom element?

While working on a project where I have a class that extends HTMLElement, I came across some interesting information in this discussion: https://github.com/Microsoft/TypeScript/issues/574#issuecomment-231683089 I discovered that I was unable to create an ...

Stopping an HTML5 range input at a specific number: Tips and tricks

Does anyone have suggestions on how to use angularjs to stop a range slider at 75? I attempted it but it doesn't seem like the best approach. Any guidance would be appreciated. [EDIT for clarification after max=75 answer] Just to clarify, I want to di ...

What is the procedure for importing material UI components into the main class?

Hey there! I'm currently working on integrating a "SimpleAppBar" element into my React app design. Below is the code snippet for this element sourced directly from the Material UI official website: import React from 'react'; import PropType ...

I'm perplexed by the inner workings of infinite ajax scroll in fetching additional posts

As someone who is new to JavaScript, I find it challenging to grasp the concept, especially when incorporating it with HTML. Despite this, I decided to experiment with infinite ajax scroll functionality. Below is my code snippet: var ias = jQuery.ias({ ...

Having trouble understanding why my submission button isn't working

I'm struggling to understand why my submit button isn't working correctly. Initially, I had an e.preventDefault() at the beginning and it didn't have any effect. However, after receiving advice from an instructor, I included it in the condit ...

What is the process for adjusting the scale value in pixels?

Is there a way to adjust the object's scale based on pixel value using three.js? object.scale.set(0.05,0.05,0.05); I am aiming to set the size at 0.05 pixels. ...