admin管理员组文章数量:1026172
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
1 Answer
Reset to default 3That 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.
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
1 Answer
Reset to default 3That 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.
本文标签: javascriptHow can you read a Firebase Data in VueJSStack Overflow
版权声明:本文标题:javascript - How can you read a Firebase Data in VueJS? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745624223a2159762.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论