Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

230
Vistas
Have an error with Realtime Database from Firebase
    // db.js file

    import * as firebase from "firebase/app"
    import "firebase/database"
    
    const config = {
        apiKey: "" ...
    }
    
    const db = firebase.initializeApp(config)
    export default db

    // App.vue file


    import { reactive, onMounted, ref } from 'vue'
    import db from "./db.js";
    
    const SendMessage = () => {
          const messagesRef = db.database().ref("messages")
    
          if(inputMessage.value === "" || inputMessage.value === null) {
            return
          }
    
          const message = {
            username: state.username,
            content: inputMessage.value
          }
    
          messagesRef.push(message)
          inputMessage.value = ""
        }

I try to make a little chat app with Vue.js and Firebase. So i don't understand because i receive this when i try to send a message : db_js__WEBPACK_IMPORTED_MODULE_1_.default.database is not a function at Proxy.SendMessage (App.vue?3dfd:63:1)

I think it's about the import but i try to change for the V9 of firebase but that's didn't work.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Firebase V9 is build in functional aproach. Im working with firestore usually give me a sign if some thing not working.

db.js

import { initializeApp } from 'firebase/app';
import { getDatabase, ref, push, child, serverTimestamp } from 'firebase/database'

const config = {
  apiKey: "" ...
}

const firebase = initializeApp(config)
const db = getDatabase()

function addMessage(path, message) {
  message.createAt = serverTimestamp() // On database side database will assign current
  // timestamp to this field so you will be able to order data
  // from newest to oldest for example.
  return push(child(ref(db, path)), message)
}
export { addMessage }

App.vue file

import { reactive, onMounted, ref } from 'vue'
import { addMessage } from "./db.js";

const SendMessage = async () => {
  if (!inputMessage.value) return 
  // line above will check are value is "" or null by throwing
  // false and using ! in front you changing it to true.

  const message = {
    username: state.username,
    content: inputMessage.value
  }

  const result = await addMessage('path to data in tree', message)
  // async/await will await until data is saved in database and then will do code bellow.
  console.log(result.key) // If you await you can read result if result is not void.
  inputMessage.value = ""
}

If you use ref() in .vue files make database operations outside of vue files database have same ref() function but they work different. You can allso change name of one function in import line import { ref as dbRef } from 'firebase/database'

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda