最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How can you read a Firebase Data in VueJS? - Stack Overflow

matteradmin8PV0评论

I followed a tutorial for Firebase, Vue.js and VueFire, but I'm having so much trouble. The database is Realtime Database, not Firestore, and all I'm getting returned when I try to look at a collection of data is either "undefined" or an object with a bunch of junk I can't understand (when I expected json). The database rules are configured to be read. What am I doing wrong?

import Firebase from "firebase";

// firebase init goes here
let config = {
  apiKey: "removed",
  authDomain: "",
  databaseURL: "",
  projectId: "",
  storageBucket: "",
  messagingSenderId: ""
};

let app = Firebase.initializeApp(config);
let db = app.database();
let postsRef = db.ref("posts");

//postsRef returns undefined. Why?!?!?

or there's this... what am I supposed to do with this:

Reference {repo: Repo, path: Path, queryParams_: QueryParams, orderByCalled_: false}
database: Database
key: "posts"
orderByCalled_: false
parent: Reference
path: Path {pieces_: Array(1), pieceNum_: 0}
queryParams_: QueryParams {limitSet_: false, startSet_: false, startNameSet_: false, endSet_: false, endNameSet_: false, …}
ref: Reference
repo: Repo {repoInfo_: RepoInfo, app: FirebaseAppImpl, dataUpdateCount: 0, statsListener_: null, eventQueue_: EventQueue, …}
root: Reference
__proto__: Query

I followed a tutorial for Firebase, Vue.js and VueFire, but I'm having so much trouble. The database is Realtime Database, not Firestore, and all I'm getting returned when I try to look at a collection of data is either "undefined" or an object with a bunch of junk I can't understand (when I expected json). The database rules are configured to be read. What am I doing wrong?

import Firebase from "firebase";

// firebase init goes here
let config = {
  apiKey: "removed",
  authDomain: "",
  databaseURL: "",
  projectId: "",
  storageBucket: "",
  messagingSenderId: ""
};

let app = Firebase.initializeApp(config);
let db = app.database();
let postsRef = db.ref("posts");

//postsRef returns undefined. Why?!?!?

or there's this... what am I supposed to do with this:

Reference {repo: Repo, path: Path, queryParams_: QueryParams, orderByCalled_: false}
database: Database
key: "posts"
orderByCalled_: false
parent: Reference
path: Path {pieces_: Array(1), pieceNum_: 0}
queryParams_: QueryParams {limitSet_: false, startSet_: false, startNameSet_: false, endSet_: false, endNameSet_: false, …}
ref: Reference
repo: Repo {repoInfo_: RepoInfo, app: FirebaseAppImpl, dataUpdateCount: 0, statsListener_: null, eventQueue_: EventQueue, …}
root: Reference
__proto__: Query
Share Improve this question edited Oct 29, 2018 at 9:47 Constantin Chirila 2,1392 gold badges20 silver badges33 bronze badges asked Oct 29, 2018 at 9:07 QuinQuin 5416 silver badges12 bronze badges 1
  • So you refer to a Collection what else than the output below do you expect? – niclas_4 Commented Oct 29, 2018 at 9:08
Add a ment  | 

1 Answer 1

Reset to default 3

That postsRef returns a Reference to the Query's location. You have methods on that ref to extract the right data.

Check the firebase api, there are a few examples there: https://firebase.google./docs/reference/js/firebase.database.Reference#key

You might want to try postsRef.toJSON() to get the JSON object you need.

Post a comment

comment list (0)

  1. No comments so far