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

Guide to adding server action listeners in a Vue.js application

I am currently working on developing a straightforward chat application using vuejs and socketio. My goal is to send messages from one user to all other users in the chat. Below is the code I have implemented on the server side to achieve this: io.on(&apo ...

How can I filter an array to retain only the initial 5 characters of every element?

I need help using the .map function to transform this array so that only the first 5 characters are displayed, like "01:00", "02:00"? This is the array: ["01:00:00 AM", "02:00:00 AM", "03:00:00 AM", "04:00:00 AM", "05:00:00 AM", "06:00:00 AM", "07:00:00 ...

Utilizing App Script for Filtering Data with Multiple Criteria

Having trouble transferring data from a data sheet to my report sheet using multiple criteria for matching. I wrote some code that worked, but it's returning all data instead of filtering by criteria. I want the function to search for column criteria ...

Managing numerous ajax forms within a single page

Upon receiving advice from the following inquiry Multiple forms in a page - loading error messages via ajax, I am endeavoring to incorporate multiple forms within one page. The goal is to insert error messages into the corresponding input div classes. I pr ...

Can JavaScript bypass the need for an html page and go directly to the printing process?

Is it possible for a user to click a "print" button and have the printer start printing? Please note that there is already a server process in place (via AJAX) that can respond with success for printing or return HTML content for display, so that is not a ...

Having trouble retrieving the JSON value as it returns undefined

Having trouble extracting specific values from JSON data. I'm trying to retrieve the value of result.datafeed[0].prod[0].vertical[0].deviceProductJson[0].product_brand, but it keeps returning as undefined. To investigate further, I examined the stru ...

What is the most effective way to implement a single modal throughout my web application without having to duplicate HTML code on each page?

After realizing I was repetitively adding the same div to every page for a modal dialog, I decided to place a single div in the site.master page and call it when needed. This method worked fine until I began implementing ajax with partial page updates. H ...

Even with employing Cors alongside Axios, I continue to encounter the following issue: The requested resource does not have the 'Access-Control-Allow-Origin' header

When working with a MEAN stack app, I had no issues with CORS. However, upon transitioning to the MERN stack, I encountered an error related to CORS despite having it implemented in the backend: Access to XMLHttpRequest at 'http://localhost:5000/api/ ...

Angular @Input set function not being activated during unit testing

Within my Component @Input('price') set setPrice(price) { this.price = price; this.modifyTotalAmount(); } Unit Testing (component.spec.ts) it('should execute function ', () => { spyOn(fixture.componentInstance, ' ...

The issue of JQuery recursion not properly focusing on a textbox

Can anyone help with a jquery focus issue I'm experiencing? My goal is to address the placeholder problem in IE by focusing on an element and then blurring it to display the placeholder. This functionality is being used in a modal form. Initially, e ...

The execution of my code differs between running it locally and in online code editors like CodePen or Plunker

Using jQuery Terminal, I have the following code: function display() { for (var i = 0; i < 100; ++i) { this.echo('line ' + i, { flush: false }); } this.flush(); setTimeout(function() { //thi ...

Fetching Data from Response Headers in Angular 4.3.3 HttpClient

(Text Editor: Visual Studio Code; TypeScript Version: 2.2.1) The main objective here is to fetch the headers of the response from a request Let's consider a scenario where we make a POST request using HttpClient within a service: import { Injec ...

Troubleshooting issues with environment variables in Next.js version 12.2.2

I tried following the steps outlined in the official documentation, but I'm encountering an issue. Here is what I did: next.config.js const nextConfig = { reactStrictMode: true, swcMinify: true, env : { MORALIS_ID: 'moralisId', ...

How to Implement Dropdowns with a vue.js Router-Link

I have set up a vue.js router and I am currently using the provided structure to insert links from an array. These links are displayed horizontally on the page. However, I am interested in changing these simple links into dropdown menus instead. Is it po ...

The use of fontawesome in vue is currently not functioning as expected

Has anyone successfully installed fontawesome in a Vue application? I've tried several tutorials, but none of them seem to work. The icons either don't show up or the plugin doesn't render at all. I prefer not to import the font using a scri ...

A few of the npm packages that have been installed globally are not functioning properly

After installing npm globally, I checked its version using npm -v and it displayed correctly as 7.13.0. Similarly, I installed heroku-cli globally, but when I ran heroku --version, it returned the error message: C:\Users\MyName\AppData&bso ...

Encountering a maximum call stack size error in Nuxtjs during development mode, and a server error 500 in production, instead of being redirected to a custom error page,

Whenever I input a URL that doesn't exist, I often encounter my personalized error message but sometimes I receive a server error (Image) Here is the content of my error.vue page : <template> <div class="error-page"> <d ...

Tips for managing and modifying information with a dropdownlist in asp.net core mvc and angular js

In my asp.net core MVC project, I am incorporating AngularJs to manage two dropdown lists and a textbox. While the textbox functionality for saving and editing data works well, I am facing issues with resetting the dropdown lists after posting data and not ...

What is the best way to pass parameters to a PHP script using AJAX to ensure they are properly processed on the server side?

I'm working with the following function: function myFunction () { $.getJSON('remote.php', function(json) { var messages = json; function check() { ... In this function, I call the remote.php script which e ...

I am attempting to embed a Vue component within another component

When trying to mount a component within another component, specifically a paginator, using props in the paginate component, I encountered an issue. The console displayed the error message "Failed to mount component: template or render function not defined. ...