[英]How to import firebase reference from a method inside another component?
I am import a firebase at the top of my /buildings.vue component: 我将Firebase导入到/buildings.vue组件的顶部:
...
import buildingsadd, { buildingsRef } from './buildingsadd.vue';
export default {
firebase() {
return {
buildings: buildingsRef
}
},
components: {
buildingsadd
},
name: 'buildings',
...
On the the /buildingsadd.vue component I am defining a new path to the the firebase ref like this: 在/buildingsadd.vue组件上,我正在定义Firebase引用的新路径,如下所示:
...
import firebase from '../firebase-config';
import { db } from '../firebase-config';
export default {
firebase() {
return {
buildings: buildingsRef,
users: usersRef,
}
},
name: 'buildingsadd',
data () {
return {
newBuilding: {
name: '',
}
}
},
methods: {
addBuilding: function () {
let userId = firebase.auth().currentUser.uid;
let buildingsRef = db.ref('buildings/'+userId);
}
...
But I am getting this errors: 但是我得到这个错误:
Answers to this would also solve my particular problem: 答案也可以解决我的特殊问题:
Is it possible to define a variable on the firebase database references path? 是否可以在Firebase数据库引用路径上定义变量?
Vue.JS "for loop" is not displaying the items on firebase if I use the following firebase rules? 如果我使用以下firebase规则,Vue.JS“ for循环”将不会在firebase上显示项目?
Is it possible to bring the "user" object to the "top level" and access it from outside the "on.AuthSateChanged(user => .... }"? 是否可以将“用户”对象带到“顶级”并从“ on.AuthSateChanged(user => ....}”外部访问它?
How to constrain read/write rules to the users that create the nodes while keeping this structure? 如何在保持这种结构的同时将读写规则限制于创建节点的用户?
You are not exporting buildingsRef
. 您未在导出
buildingsRef
。 Export it like below. 如下导出。
buildingsadd.vue : 建筑add.vue :
import firebase from '../firebase-config';
import { db } from '../firebase-config';
let userId = firebase.auth().currentUser.uid; // added
export let buildingsRef = db.ref('buildings/'+userId); // added
export default {
// ... (all the same)
methods: {
addBuilding: function () {
// removed lines here
}
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.