javascript - 来自firebase的Vuex值分配
问题描述
我使用此代码将数据从 firebase 实时数据库下载到我的 vuex 商店。
firebase.database().ref('Profiles').child(firebase.auth().currentUser.uid).once('value')
.then((data) => {
var obj = data.val()
console.log("DATA.VAL().votedQuests", data.val().votedQuests)
const profile = {
id: obj.id,
votedQuests: data.val().votedQuests,
}
结果在 data.val().votedQuests 我得到:
console print:
DATA.VAL().votedQuests: -M3pc4Bf4bSjqeSw1CvB: "Tak"
什么是正确的:
但是当我这样做时:
const profile = {
id: obj.id,
votedQuests: data.val().votedQuests,
}
或者
const profile = {
id: obj.id,
votedQuests: obj.votedQuests,
}
并尝试在 console.log("Profile",profile) 中打印结果,我得到了这个视图:
console print:
votedQuests: Object
-M3pc4Bf4bSjqeSw1CvB: "Tak"
rbFeBq6lckgH7k1KZr419Gz9cGJ3: undefined //this key rbFeB... is uid of user. It should not be here.
你能向我解释为什么这个键rbFeBq6lckgH7k1KZr419Gz9cGJ3: undefined
在我的 votedQuests 下,而在 firebase 中它不存在吗?
当我 在正确obj.votedQuests
之前检查值时,更重要的是。const profile{...}
解决方案
推荐阅读
- node.js - 从 Vue 调用时出现 Koa 404
- mysql - 如何在 SQL 中创建前 5 列和后 5 列?
- webpack - 如何修复您可能需要适当的加载器来处理此文件类型,目前没有配置加载器来使用 webpack 4 处理此文件
- reactjs - 打开 Drawer 的 AppBar 可以垂直放置在应用的左侧吗?
- azure - 如何在 ADFS 上使用 openid 对同步用户进行身份验证?
- sql - 如何从一行中插入不同的列?
- java - 我无法从 string.xml 中存在的整数数组中取出元素
- android - 在 webview/webkit 中以编程方式按下按钮
- perl - Perltex:如何输出到乳胶文件?
- amazon-web-services - 在无需公开 s3 存储桶的情况下,最接近在 S3 中执行符号链接功能的方法是什么?