Tips for retrieving information from a Vuetify modal window

Is it possible to retrieve data from a dialog in the VueJS Vuetify framework? Specifically, how can I access the username or password entered in the NewUserPopup.vue dialog from app.vue?

  • App.vue = main template
  • NewUserPopup.vue = Dialog template imported in app.vue



The Dialog NewUserPopup.vue:

<template>
  <v-dialog v-model="dialog" max-width="600px">
    <template v-slot:activator="{ on }">
      <v-btn v-on="on" color="primary" class="mb-3">Add new user</v-btn>
    </template>
    <v-card>
      <v-card-title>
        <h3 class="primary--text">Add a New User</h3>
      </v-card-title>
      <v-card-text>
        <v-form class="px-3">
          <v-text-field label="Username" v-model="username" prepend-icon="account_box"></v-text-field>
          <v-text-field label="Firstname" v-model="firstname" prepend-icon="person"></v-text-field>
          <v-text-field label="Lastname" v-model="lastname" prepend-icon="person"></v-text-field>
          <v-text-field :type="'password'" label="Password" v-model="password" prepend-icon="edit"></v-text-field>
          <v-card-actions>
            <v-spacer></v-spacer>
            <v-btn class="primary mx-0 mt-3" @click="submit" >
              Add User
              <v-icon right>done</v-icon>
            </v-btn>
          </v-card-actions>
        </v-form>
      </v-card-text>
    </v-card>
  </v-dialog>
</template>

<script lang="ts">
export default {
  data () {
    return{
      dialog: false,
      username: '',
      firstname: '',
      lastname: '',
      password: '',
    }
  },
  methods:{
    submit(){
      this.dialog = false;
    }
  }
}
</script>


The Main App.vue:

<template>
  <v-app >
    <new-user-popup></new-user-popup>
  </v-app>
</template>

<script lang="ts">
import Vue from 'vue';
import NewUserPopup from './components/NewUserPopup.vue'


export default {
  name: 'App',
  components:{
    NewUserPopup
  },

  data () {
    return{

    }
  },
};
</script>

How can I go about accessing this data?

Answer №1

There are two options available:

The first option is to set up a store with both a password and a username. Alternatively, you can define the username and password directly in the App.js file, send them as props to your dialog component, and trigger the change event.

Answer №2

Communication between child and parent components in Vue.js

The NewUserPopup.vue Dialog Component:

<template>
  <v-dialog v-model="dialog" max-width="600px">
    <template v-slot:activator="{ on }">
      <v-btn v-on="on" color="primary" class="mb-3">Add new user</v-btn>
    </template>
    <v-card>
      <v-card-title>
        <h3 class="primary--text">Add a New User</h3>
      </v-card-title>
      <v-card-text>
        <v-form class="px-3">
          <v-text-field label="Username" v-model="model.username" prepend-icon="account_box"></v-text-field>
          <v-text-field label="Firstname" v-model="model.firstname" prepend-icon="person"></v-text-field>
          <v-text-field label="Lastname" v-model="model.lastname" prepend-icon="person"></v-text-field>
          <v-text-field :type="'password'" label="Password" v-model="model.password" prepend-icon="edit"></v-text-field>
          <v-card-actions>
            <v-spacer></v-spacer>
            <v-btn class="primary mx-0 mt-3" @click="submit" >
              Add User
              <v-icon right>done</v-icon>
            </v-btn>
          </v-card-actions>
        </v-form>
      </v-card-text>
    </v-card>
  </v-dialog>
</template>

<script lang="ts">
export default {
  data () {
    return{
      dialog: false,
      model:{}
    }
  },
  methods:{
    submit(){
      this.dialog = false;
      this.$emit('userInfo',this.model)
    }
  }
}
</script>


The Main App.vue:

<template>
  <v-app >
    <new-user-popup @userInfo="getUserData($event)"></new-user-popup>
  </v-app>
</template>

<script lang="ts">
import Vue from 'vue';
import NewUserPopup from './components/NewUserPopup.vue'


export default {
  name: 'App',
  components:{
    NewUserPopup
  },

  data () {
    return{

    }
  },
  methods:{
    getUserData(value){
      console.log(value)
    }
  }
};
</script>

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

Bidirectional Data Binding with Computed Setter in Vue.js

Exploring the concept of two-way data binding with a basic example: <template> <input v-model="fullname"/> <input v-model="first"/> <input v-model="last"/> </template> <script> var app = new Vue({ el: '#a ...

There seems to be a problem with the Chart property getter as it

I'm in the process of creating an object that corresponds to chartJS's line-chart model <line-chart :data="{'2017-05-13': 2, '2017-05-14': 5}"></line-chart> There is an API I utilize which returns a standard arra ...

Guide to TypeScript, RxJS, web development, and NodeJS: A comprehensive manual

Looking for recommendations on advanced web development books that focus on modern techniques. Digital resources are great, but there's something special about reading from a physical book. I don't need basic intros or overviews - consider me an ...

Transform Material UI Typography to css-in-js with styled-components

Can Material UI elements be converted to styled-components? <Container component="main" maxWidth="XS"> <Typography component="h1" variant="h5"> Sign in </Typography> I attempted this for typography but noticed that t ...

Try skipping ahead to the following spec file even if the initial spec has not been completed yet

I have encountered an issue when trying to execute two spec files for Angular.js. The problem arises when I attempt to run both files consecutively - the browser initially opens for angular.js, then switches to angularCal.js without executing angular.js ...

Tips for successfully importing $lib in SvelteKit without encountering any TypeScript errors

Is there a way to import a $lib into my svelte project without encountering typescript errors in vscode? The project is building and running smoothly. import ThemeSwitch from '$lib/ThemeSwitch/ThemeSwitch.svelte'; The error message says "Canno ...

Utilizing Symfony 4, Twig, and VueJS for Seamless Routing between Components

Currently diving into Symfony 4 with Twig templating and leveraging VueJS for UI elements. I've created a simple component in a .vue file to display tasks, which at the moment just generates a basic table. // task-list.vue <template> < ...

Turn off hover effect for the v-checkbox component in Vuetify 2

Is there a way to prevent the darkened circle from appearing behind a v-checkbox in Vuetify 2 when hovering over it? My v-checkbox is currently enclosed within a v-tab and a v-tooltip, although I'm not sure if that has any impact. <v-tab v-for=&quo ...

The JavaScript code is executing before the SPFX Web Part has finished loading on the SharePoint page

I recently set up a Sharepoint Page with a custom masterpage, where I deployed my SPFx Webpart that requires certain javascript files. While the Webpart functions correctly at times, there are instances when it doesn't work due to the javascript bein ...

Building a VueJS component with custom data properties and methods

I am facing an issue while trying to create a custom DataSource object for a table component in VueJS. It seems that Vue is making the object reactive which is causing some trouble. While I can access the direct data values like this.dataSource.columns or ...

Navigate to the specific page using the router-link with the designated path

I have 10 different filters displayed in a table and I want each filter name to link to a specific page. Here is an example of my table row: <md-table-row v-for="(row, index) in manage" :key="index"> In the first cell of the table, I'm trying ...

What is the best way to access the input element of ng-content from the parent component?

Creating a unique component in the following structure <div class="custom-search-field" [ngClass]="{'expanding': expanding}"> <ng-content></ng-content> </div> When using this component, users are expected to include ...

Assign a value using the select component from Material UI

I just finished creating a dropdown menu const [selectedValue, setSelectedValue] = useState(''); const handleSelectionChange = (e: any) => { //setSelectedValue(e) console.log('value', selectedValue) } .... <Fo ...

Generate a fresh array using the data from the existing array object

I have nested objects within arrays that I need to manipulate. { "page": [ { "num": "1", "comp": [ { "foo": "bar", "bar": "foo", ...

Are you familiar with Vue.JS's unique router options: the 'history' and 'abstract' routers?

Currently, I am developing a VueJS application that involves a 5-step form completion process. The steps are linked to /step-1 through /step-5 in the Vue Router. However, my goal is for the site to return to the main index page (/) upon refresh. One solu ...

sending properties to dynamically loaded components

I'm struggling with transferring props between children and parent components using Vue Routes. Within my Layout component, I have a wrapper DIV structured like this: <template> <div class="container" v-bind:class="cssClass ...

Unable to display the attributes of an object using console.log

I am attempting to log the properties of an object in TypeScript, but I am encountering issues. setTitleAndBody(result: { title: String; body: String; }) { console.log(result) console.log(result.title) } What's interesting is that if I only l ...

Leveraging Vue.js's capabilities with an external setup file

Is it feasible for a Vue App to access an external configuration file? I envision a setup where I deploy the application along with the config file; then, I should be able to modify the configuration in the external file without needing to rebuild the enti ...

Having trouble installing npm package in Angular project

After cloning my project from GitLab, I encountered an issue while trying to install the NPM packages. When I ran npm install, an error popped up: https://i.stack.imgur.com/WNT5s.png Upon checking the log file, I found the following error message: 3060 ...

Is there a way to ensure that a "catch all other" route in the Vue Router will also capture the URL if a portion of it matches a predefined route?

After following the suggestion to implement a catch all route from this article, I realized that it does not capture URLs that partially match a defined route. routes: [ { path: "/album/:album", name: "album", component: Album, } ...