[Vuejs]-Delete key using Vue Resource

0๐Ÿ‘

I resolve this using vuefire

npm install vuefire firebase --save

Script:

import { setTimeout } from 'timers';
import { db } from '../config/db';
let booksRef = db.ref('data')

  export default {
    data: () => ({
      books: []
    }), 
    firebase: {
      books: booksRef
    },
    methods: {
      show(book) {
        book.show = !(book.show);
      },
      deleteBook(book) {
        debugger;
        booksRef.child(book.id).remove();
      }
    },

The config db you can export from firebase.

0๐Ÿ‘

this.$http.delete(`data/${book.id}.json`)
   .then(response => {
         return response
         }.catch(err => {
         // error callback
           return err
        })

  this.$http.delete(`data/${book.id}.json`)
   .then(() => {
          const index = this.array.findIndex((i) => {
                return i.id === id 
            })
            if (index > -1) {
                this.array.splice(index, 1)
            }
         }.catch(err => {
         // error callback
           return err
        })

This worked for me, you could as well try it, or return a function that would delete it locally instead of just returning the response like the second example above

Leave a comment