Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
problem deleting document Vuejs Firestore

I am creating site for my store and learning Vue js at the same time. I'm having a problem with delete product using id. I'm using Vue js 3 and Firebase 9.

I have this on main.j

const dataBase = collection(db, "products");

and this on products.js

import { dataBase } from '../main';
import { addDoc, deleteDoc, onSnapshot, doc } from "firebase/firestore";

export default {
  name: "Products",
  props: {
    msg: String
  },
  data() {
    return {
      products: [],
      product: {
        name: '',,
        price: '',
        brand: '',
        category: ''
      }
    }
  },
  methods: {
    saveData() {
      try {
        addDoc(dataBase, this.product).then((docRef) => {
          console.log("Document written with ID: ", docRef.id);
        })
      } catch (e) {
        console.error("Error adding document: ", e);
      }
    },
    deleteProduct(doc) {
      if (confirm('Видалити ?')) {
        deleteDoc(doc(dataBase, "products", docRef.id));
      } else {

      }
    }
  },
  created() {
    onSnapshot(dataBase, (snapshot) => {
      snapshot.docs.forEach((doc) => {
        this.products.push({ ...doc.data(), id: doc.id })
      })
    });
  }
};

Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think it's a typo issue, instead of docRef.id you need right doc.id

deleteProduct(doc) {
  if (confirm('Видалити ?')) {
    deleteDoc(doc(dataBase, "products", doc.id));
  } else {

  }
} 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!