简体   繁体   English

属性或方法“名称”未在实例上定义,但在渲染期间被引用

[英]Property or method "names" is not defined on the instance but referenced during render

i'm creating a CRUD using vuejs and Firebase, but I don't know how to fix this error, [Vue warn]: Property or method "names" is not defined on the instance but referenced during render.我正在使用 vuejs 和 Firebase 创建一个 CRUD,但我不知道如何解决这个错误, [Vue warn]: Property or method "names" is not defined on the instance but referenced during render.

So I can add information to the real time database, however, I can not show the data inside the database tables to my Vuejs application.所以我可以向实时数据库添加信息,但是,我无法将数据库表中的数据显示给我的 Vuejs 应用程序。 someone can help me?有人可以帮助我吗?

this is my firebase.js这是我的 firebase.js

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 usando VUEJS + Firebase
      <hr>
      <div class="formulario">
        <label>
          Nome:
        </label>
        <input type="text" v-model="nome"/>
        <br>
        <label>
          Profissão:
        </label>
        <input type="text" v-model="job" />
        <br>
        <button @click="addPessoa">
          Adicionar
        </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 {
      nome: '',
      job: ''
    }
  },
  firebase:{
    names:namesRef
  },
  methods: {
    addPessoa(){
      namesRef.push({nome: this.nome, 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 Result: Data saved to Firebase is rendered on the view预期结果:保存到 Firebase 的数据呈现在视图上

Reality: [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.现实: [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. [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.

It will help me a lot to solve this problem.它将对我解决这个问题有很大帮助。 I hope my mother tongue doesn't get in the way.我希望我的母语不会妨碍到我。

You've installed the Cloud Firestore plugin but you're trying to use the Realtime Database.您已安装 Cloud Firestore 插件,但您正在尝试使用实时数据库。

Use this instead in your main.js file在您的main.js文件中使用它

import { rtdbPlugin } from "vuefire"

Vue.use(rtdbPlugin)

See https://vuefire.vuejs.org/vuefire/getting-started.html#pluginhttps://vuefire.vuejs.org/vuefire/getting-started.html#plugin


You also need to import the Firebase database component.您还需要导入 Firebase 数据库组件。 In your firebase.js script...在您的firebase.js脚本中...

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

See https://firebase.google.com/docs/web/setup#using-module-bundlers请参阅https://firebase.google.com/docs/web/setup#using-module-bundlers

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未在实例上定义属性或方法(…),但在渲染期间引用了该属性或方法 - Property or method (…) is not defined on the instance but referenced during render 属性或方法“_”未在实例上定义,但在渲染期间引用 - Property or method "_" is not defined on the instance but referenced during render [Vue警告]:属性或方法未在实例上定义,但在渲染期间被引用 - [Vue warn]:Property or method is not defined on the instance but referenced during render 属性或方法“greet”未在实例上定义,但在渲染期间被引用 - Property or method “greet” is not defined on the instance but referenced during render Nuxt。 属性或方法“posts”未在实例上定义,但在渲染期间被引用 - Nuxt. Property or method "posts" is not defined on the instance but referenced during render VueJS:属性或方法......未在实例上定义,但在渲染期间被引用 - VueJS: Property or method ... is not defined on the instance but referenced during render Vue:属性或方法“APP”未在实例上定义,但在渲染期间引用 - Vue: Property or method “APP” is not defined on the instance but referenced during render 未在实例上定义但在渲染期间引用的属性或方法 I Vuex - Property or method not defined on the instance but referenced during render I Vuex [Vue 警告]:属性或方法“hp”未在实例上定义,但在渲染期间引用 - [Vue warn]: Property or method "hp" is not defined on the instance but referenced during render [Vue warn]: 属性或方法未在实例上定义但在渲染期间被引用 - [Vue warn]: Property or method is not defined on the instance but referenced during render
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM