Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda