Add Firebase Data to Dropdown

Utilizing Vuetify to build a dropdown has been an interesting challenge for me. While I can successfully select a value and store it in the firebase database, I'm facing difficulties when it comes to repopulating the dropdown after page refresh.

Below is the template structure:

<template>
        <v-select
              v-bind:items="itemsPhone"
              v-model="telephoneType1"
              id="telephone-pro-type-1"
              label="Select"
              single-line
              bottom
         > </v-select>
</template>

<script>
export default {
   data () {
     return {
       telephoneType1:'',
       itemsPhone: [
             { text: 'Mobile' },
             { text: 'Emergency' },
             { text: 'Weekend' }
           ],
     }
</script>

The code snippet below focuses on populating fields, although my attempts to populate the dropdown have proven unsuccessful.

mounted(){
  var that = this;
  var query = db.ref('Clients/'+ clientName +'/'); // shortened 

  query.once('value')
         .then((snapshot) => {

                that.emailPro = snapshot.child('emailPro').val();
                that.telephoneType1 = snapshot.child('telephoneType1').val();
         });


}

I've experimented with various methods, including vanilla JavaScript, trying to push values into the dropdown by targeting specific classes or IDs, but unfortunately, they don't seem to populate as expected.

Answer №1

The label attribute is utilized to establish a default value. Instead of setting it to 'Select', consider setting telephoneType1 : 'Select

Make sure to set the label to that attribute:

<v-select
         v-bind:items="itemsPhone"
         v-model="telephoneType1"
         id="telephone-pro-type-1"
         :label="telephoneType1"
         single-line
         bottom
> </v-select>

Additionally, your code appears verbose as you are using fat arrow functions (=>), which eliminates the need for setting that=this. Fat arrow functions automatically preserve the context of this, so you can rewrite the code like this:

mounted(){  
  var query = db.ref('Clients/'+ clientName +'/'); // shortened 

  query.once('value')
         .then((snapshot) => {

                this.emailPro = snapshot.child('emailPro').val();
                this.telephoneType1 = snapshot.child('telephoneType1').val();
         });


}

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

Utilize MetroUiCSS to effortlessly integrate a sleek calendar into your AngularJS application

I'm looking to incorporate a calendar from Metro Ui CSS into my project. Here is the link to the calendar: However, I am struggling with how to activate the calendar. I have already included all necessary scripts in my index.html (3 scripts) and have ...

Exploring the idea of nesting Angular components with dynamic data

I am attempting to create a nested structure using multiple components in the following way. My objective is to pass user data into the user-item component without directly including the item component inside the list component. Main-App <app-user-li ...

Extract the <img> element from the Angular model property

I'm currently leveraging Angular to display some HTML content: <p class="description" ng-model="listing.Description"></p> When the content is rendered, it includes images within the text, which is acceptable. However, now I aim to ident ...

How can you use CSS animations to animate two images in a way that hides one while showing the other?

click here for the image link visit this webpage for the link I need I am looking to add an animated section to my website. The inspiration comes from the webpage linked above, where images slide down one after another in a seamless manner. I attempted t ...

What could be causing Vue to cease functioning after rendering two pages in a cshtml file?

Coming from a very beginner level in programming, I am currently working on developing a website using asp.net MVC. However, after rendering a view page to _layout, the vue in the _layout suddenly stopped working and an error message appeared in the conso ...

What is the best way to pass parameters in jQuery using .on()?

Hello there, I have a slight dilemma :) Could you please advise me on how to pass a parameter to an external JavaScript function using the .on method? Here is the code snippet: <script> var attachedPo = 0; $this.ready(function(){ $ ...

How can I implement callback functions in joi validation?

Exploring the World of Coding I came across a code snippet online that caught my attention, but upon closer inspection, I realized it used Hapi/Joi which is now considered outdated. My question is how can I modify this code to work with Joi? app.post(&apo ...

Combine various input data and store it in a variable

I am looking for a way to add multiple input text values together and store the sum in a variable. Currently, I can add the values and display it in an id, but I want to assign it to a variable instead. The condition for this variable is described below af ...

Is there a way to refresh a table automatically whenever a specific row is added or removed?

I am currently in the process of learning Vue.js with Laravel. I have encountered an issue where the deletion function is working correctly, but the row is not removed from the index page until it is reloaded. Additionally, when a new category is added, th ...

A step-by-step guide on setting up an event listener for dynamically generated HTML using JavaScript objects

In my JavaScript code, I am creating object instances that include HTML elements in the form of buttons. These buttons are dynamic and have words generated dynamically as well. I want these buttons to execute certain functions when clicked. The challenge I ...

Triggering an Ajax call for form validation only occurs when the form is not validated

I am struggling with a simple form that has an Ajax call, but the ajax call gets executed even if the form is not validated. In the code snippet below, the line console.log("This line should execute only if Form is validated"); gets executed when the form ...

What is the best way to uninstall the Google Translation Plugin when transitioning to a new Vue component?

I'm facing a minor issue as I develop a website builder. It consists of two main parts: the builder and the preview section. Within the preview, I've included the Google Translation plugin: onMounted(() => { new google.translate.TranslateEle ...

Within an Angular test scenario, execute a static method from a service that triggers an HTTP get request to fetch stored JSON data. This data is then retrieved and returned back to the service

Currently, I am facing a challenge in my Angular test case where I am trying to load JSON data via an HTTP call. The issue arises when a static method is called from a service spec file named "url-service.spec" to another service named "load-json.service. ...

When PHP is connected to the database, Ajax remains inactive and does not perform any tasks

I am currently working on setting up a simple connection between JavaScript and my database using ajax and PHP. The goal is for JavaScript to receive a name from an HTML form, make changes to it, send it to PHP to check if the name already exists in the da ...

Struggling to integrate vue js into Laravel

I recently developed a character counter feature for SEO input fields using Vue JS. It functioned flawlessly on jsfiddle, however, upon integrating it with Laravel, I encountered an issue. Instead of displaying the number of characters remaining, it showed ...

Executing a Firebase query when a button is clicked and refreshing the RecyclerView with the fetched

I am currently working on running a query on my Firebase database to retrieve only those records where the timestamp matches the date selected in the date picker within the app interface. I want this query to be executed every time I click on the "view rec ...

Even after applying trim() function, PHP's return statement still adds spaces unnecessarily

My function is supposed to return a boolean, but for some reason, it is adding spaces at the beginning of the string. Even after using trim(), the spaces persist. What could be causing this unexpected behavior? PHP function checkFile($v){ $result = is_ ...

Troubleshooting Recursive Logic Problem with hasOwnProperty in JavaScript and JSON

JSON data with a specific problem highlighted by the comment // doesn't get parsed currently: var oarsObject = [{ "coordinateReferenceSystem": "26782,15851 <-- not in a value", "positionReferenceType": "geogWgs84", "geogWgs84": ...

Transitioning to Material-ui Version 4

During the process of upgrading material-ui in my React Application from version 3.9.3 to version 4.3.2, I encountered an error message stating TypeError: styles_1.createGenerateClassName is not a function. I am feeling lost when it comes to transitioning ...

I encountered an error with the TS1003 code in Angular because an identifier was expected on the throw import statement. Upon further investigation, I realized that the issue originated from

I came across this piece of code: import { Observable, throw} from 'rxjs'; An error message popped up saying identifier expected: ERROR in config/config.service.ts(3,22): error TS1003: Identifier expected. The error appears to be related to ...