The instance does not have a definition for the property or method "names" that is being referenced during rendering

Currently, I'm working on developing a CRUD application using Vue.js and Firebase. However, I've encountered an error that I can't seem to resolve:

[Vue warn]: Property or method "names" is not defined on the instance but referenced during render.

While I am able to successfully add information to the real-time database, I'm facing difficulties in displaying the data from the tables inside the database in my Vue.js application. Can someone offer assistance with this?

This snippet shows my firebase.js setup:

import firebase from 'firebase';

const firebaseConfig  = {
        apiKey: "AIzaSyBDWnEjj0OJayCxR4kJl4iDn9LocDGVcw8",
        authDomain: "operand-teste-front-end.firebaseapp.com",
        databaseURL: "https://operand-teste-front-end.firebaseio.com",
        projectId: "operand-teste-front-end",
        storageBucket: "operand-teste-front-end.appspot.com",
        messagingSenderId: "648371507080",
        appId: "1:648371507080:web:6030b3583a933b69e2b43d",
        measurementId: "G-RN0RCH48Y4"
    }
    const firebaseApp = firebase.initializeApp(firebaseConfig)

    export const db = firebaseApp.database()
    export const namesRef = db.ref('names');
    export const jobRefs = db.ref('jobs')

main.js

import Vue from 'vue'
import App from './App.vue'
import './Firebase'
import { firestorePlugin } from 'vuefire'

Vue.use(firestorePlugin)

new Vue({
  el: '#app',
  render: h => h(App)
})

App.vue

<template>
  <div id="app">
    <div>
      CRUD using VUEJS + Firebase
      <hr>
      <div class="formulario">
        <label>
          Name:
        </label>
        <input type="text" v-model="name"/>
        <br>
        <label>
          Job:
        </label>
        <input type="text" v-model="job" />
        <br>
        <button @click="addPerson">
          Add
        </button>
      </div>
    </div>
    <div>
        <ul>
          <li v-for="personName in names" :key="personName['.key']">
              {{personName}}
          </li>
        </ul>
      </div>
  </div>
</template>

<script>
import {jobRefs,namesRef} from './Firebase'
export default {
  data () {
    return {
      name: '',
      job: ''
    }
  },
  firebase:{
    names:namesRef
  },
  methods: {
    addPerson(){
      namesRef.push({name: this.name, edit: false})
      jobRefs.push({job: this.job, edit: false})
    }
  }
}
</script>

<style>
#app {
  font-family: Arial, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

h1, h2 {
  font-weight: normal;
}

ul {
  list-style-type: none;
  padding: 0;
}

li {
  display: inline-block;
  margin: 0 10px;
}

a {
  color: #42b983;
}
.formulario{
  width: 170px;
  border: 3px aqua solid;
  margin: 20px auto;
  background-color: rgb(102, 201, 255);
}
button{
  border: 2px;
  background-color: transparent;
}
</style>

Expected Outcome: Displaying the data saved in Firebase on the view

Current Issue:

[Vue warn]: Property or method "names" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

Your assistance in resolving this problem would be highly appreciated. Thank you!

Answer №1

If you've added the Cloud Firestore plugin but are attempting to utilize the Realtime Database, follow these steps:

Instead of main.js, add the following code:

import { rtdbPlugin } from "vuefire"

Vue.use(rtdbPlugin)

For more information, visit


Don't forget to import the Firebase database component in your firebase.js script...

import firebase from "firebase/app"
import "firebase/database"

Further details can be found at https://firebase.google.com/docs/web/setup#using-module-bundlers

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

What happens if you try to add a member to a Mailchimp list who is already on the list

After following Angela Yu's course for the past few weeks, I attempted to implement the Mailchimp API as she demonstrates. However, I encountered difficulties due to recent changes in Mailchimp. Despite this setback, I was able to find the API referen ...

The EJS template on the Express app is encountering an issue: it is unable to find the view "/id" within the views directory located at "/home/USER/Desktop/scholarship-app/views"

When attempting to render the request URL for an ID in my Express app, I encountered the following error: Error: Failed to find view "/id" in views directory "/home/USER/Desktop/scholarship-app/views" Here is a portion of my Express app code: app.get(&a ...

Adding a Timepicker to a Datepicker on a jsp webpage with javascript

I am working on a JSP page that includes a date picker. I want to enhance this datepicker by adding a start time and end time within the calendar itself. How can I achieve this? Additionally, I need to implement validation ensuring that the start time is a ...

Using Javascript in n8n to merge two JSON arrays into a single data structure

When working on a project, I extract JSON objects from the Zammad-API. One of the tickets retrieved is as follows: [ { "id": 53, "group_id": 2, "priority_id": 2, "state_id": 2, "organizati ...

After the jquery.show function is executed, an unexpected WebDriverException occurred, indicating an unknown error that prevents focusing

Here is my line of JavaScript code: $('#name').show(); And this is my webdriver code line: wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("name"))).sendKeys("Some Name"); When running the test, I encountered an exception: Web ...

Looking to include a new item into an array with the help of AngularJS

Having just started with angularJS, I am facing difficulties in adding an object from a form to an array. When I click on "Add New Product", it triggers the "newItemModal". I enter the new product information but the submit button doesn't seem to work ...

What is the best way to adjust the maximum width of Reddit's embedded comment iframe?

Reddit provides a code that can be embedded to display their comments on a website, As an example: <div class="reddit-embed" data-embed-media="www.redditmedia.com" data-embed-parent="false" data-embed-live="false" data-embed-uuid="24a3e666-f855-4664 ...

Searching for particular information within an array of objects

Seeking guidance as a newbie on how to extract a specific object from an array. Here is an example of the Array I am dealing with: data { "orderid": 5, "orderdate": "testurl.com", "username": "chris", "email": "", "userinfo": [ ...

Can you help identify the issue in this particular ajax code?

Here is the code I wrote to check if a username exists in the database using Ajax. However, I am facing an issue where the input text from the HTML page is not being sent to the checkusername.php file via $_POST['uname'];. I have tried multiple s ...

I'm a beginner with Angularjs and I attempted to populate multiple JSON values, but unfortunately, it didn't work as expected

<div ng-controller="studentController" ng-repeat = "student in students | unique = 'RollNo' " > <table class="profile-info"> <tr> <th>Enrollment Number</th> <td> ...

Steps for transforming an Array of hierarchical data into the correct JSON format for D3 Tree Region visualization

I am struggling with converting an array of hierarchy data into the correct Object format. Here is what I am trying to convert: [ {"PARENT_ID": 0,"CHILD_ID": 1,"NAME": "Quality","LEVEL_A": 0}, {&qu ...

Function in nodejs throwing an error: Return type missing

I am facing an issue with this code snippet while trying to compile the application. public async test(options?: { engine?: Config }): Promise<any> { const hostel = new Service({ list: this.servicesList, createService ...

Struggling to extract text from within a <p> tag on an Ionic 1 app page on iOS

After developing an ionic-1 application for iOS and Android devices, I encountered an issue with displaying mobile numbers in one of the views. The numbers are contained within <p> tags. While users can click and hold on a number to copy it on Andr ...

The collapsible tree nodes overlap one another in the D3.js visualization

I'm currently working on integrating a d3 code into Power BI for creating a collapsible tree structure. Each node in the tree is represented by a rectangular box, but I've run into an issue where nodes overlap when their size is large. Below is t ...

Is there a way to convert the text within a div from Spanish to English using angular.js?

I am working with a div element that receives dynamic text content from a web service in Spanish. I need to translate this content into English. I have looked into translation libraries, but they seem more suited for individual words rather than entire dyn ...

onChange does not trigger useEffect

In the Order Content component, I am receiving some products as props to be used in a select component. When a product is selected in the dropdown, it triggers the rendering of Summary and Product components. In these components, the user can choose the ...

PHP Calculator with Dynamic Calculations

I need to create an order form that updates the tax and total automatically once a quantity is entered into the text box. Should I use PHP or JavaScript for this functionality? Let's assume, for instance, that the tax rate is 0.3% My requirements: ...

What is the method for utilizing underscores in Visual Studio Code without the need to "enable" them beforehand?

I attempted to utilize underscore in Visual Studio Code and found that it only works if I include this line of code at the beginning: var _ = require('underscore'); The output functions properly with this code in place. However, if I remove it, ...

Tips for creating a clickable A href link in the menu bar that triggers an accordion to open in the body when clicked - html

Is there a way to open the first accordion when clicking on the "open 1st accordion" link, and do the same for the second link? The accordions themselves work perfectly fine, I just need a way to trigger them from outside their scope by clicking on links i ...

Encountering an issue in next.js with dynamic routes: getting a TypeError because the property 'id' of 'router.query' cannot be destructured since it is undefined

I am working on creating a dynamic page in next.js based on the ID. Here is the basic structure of my project: File path: app/shop/[id]/page.tsx This is the code snippet: "use client" .... import { useEffect, useState } from 'react' ...