Skip to content
Advertisement

How do I add files from form to Firebase database? Vue js + Vuetify + Firebase

This is my first time using both Vuetify and Firebase.

Following a tutorial, I was trying to add some data to my db in firebase (not images).

After installing firebase in my project with npm, I’ve set it up in a separate js file like this:

JavaScript

In the vue.js file where I have the form for the new object with data that I want to add, I’m trying to do like this:

Template:

JavaScript

Script:

JavaScript

The error logged is “TypeError: Cannot read properties of undefined (reading ‘collection’)”

I know I am probably importing something the wrong way, but I am very new to this and I didn’t get a good grasp at it yet.

I want to upload the object coming from the form to the Firebase db, could you explain me how to and what I am missing with the usage of fire base?

Also my npm version is 8.3.1 (I can’t update it atm) is it a problem?

UPDATE:

The solution offered by Frank van Puffelen worked but I still could not get it to work as long as firebase set up was in an external js file, as long as I pasted out everything in the file where I was calling the submit method, it worked!

Advertisement

Answer

You’re importing Firestore like this:

JavaScript

This is the syntax for the “new” v9 version of the SDK, which uses a modular syntax. But then you’re trying to call:

JavaScript

This is the namespaced syntax for the older SDKs. You can’t mix and match the syntax like that.

In the modular syntax, the equivalent call would be:

JavaScript

Also see:

Advertisement