@Radiss

Почему не добавляются данные в Firebase (Realtime Databаse)?

Возникла проблема с добавлением данных бд.
При попытке добавить ad - вылетает error "Reference.push failed: first argument contains undefined in property 'books.ownerId"
Возможно, причина в версиях Vuifire?
У меня уст. firebase": "^6.6.1"
"@firebase/database": {
"version": "0.5.3",

На stack overflow, нашёл похожий вопрос и решение (

:"I have finally discovered the source of this issue and how to fix.

Some of the confusion was caused by the fact that, since my app is still in early development it was actually loading Vuefire from CDN rather than from a local dependency.
Recently Vuefire devs have changed from 1.x to 2.x as their official stable release. That said, it would seem that in 2.x (now the stable channel) and 3.x (next pre-release candidate) releases, with the main focus shifting to Cloudstore, there are now major problems with Realtime Database implementations.
After downgrading Vuefire to version 1.4.5 (latest 1.x release) all of my original source code is once again working as expected."

Как сделать это добавление без понижения версии?
Или как понизить версию Vuefire через npm к примеру?

Код store/ad.js

spoiler

import * as fb from 'firebase'

class Ad {
  constructor (title, description, ownerId, imageSrc = '', promo = false, id = null) {
    this.title = title
    this.description = description
    this.ownerId = ownerId
    this.imageSrc = imageSrc
    this.promo = promo
    this.id = id
  }
}

export default {
  state: {
    ads: [
      {
        title: 'First ad',
        description: 'Hello i am description',
        promo: false,
        imageSrc: '',
        id: 'vnvjn'
      },
      {
        title: 'Second ad',
        description: 'Hello i am description',
        promo: true,
        imageSrc: '',
        id: 'fvjfj'
      },
      {
        title: 'Third ad',
        description: 'Hello i am description',
        promo: true,
        imageSrc: '',
        id: 'fhdh'
      }
    ]
  },
  mutations: {
    createAd (state, payload) {
      state.ads.push(payload)
    }
  },
  actions: {
     async createAd ({commit, getters}, payload) {
     commit('clearError')
      commit('setLoading', true)

      try {
        const newAd = new Ad(
          payload.title,
          payload.description,
          getters.user.id,
          payload.imageSrc,
          payload.promo
        )

        const ad = await fb.database().ref('ads').push(newAd)

        commit('setLoading', false)
        commit('createAd', {
          ...newAd,
          id: ad.key
        })
      } catch (error) {
        commit('setError', error.message)
        commit('setLoading', false)
        throw error
     }
    }
  },
  getters: {
    ads (state) {
      return state.ads
    },
    promoAds (state) {
      return state.ads.filter(ad => {
        return ad.promo
      })
    },
    myAds (state) {
      return state.ads
    },
    adById (state) {
      return adId => {
        return state.ads.find(ad => ad.id === adId)
      }
    }
  }
}

  • Вопрос задан
  • 29 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы