【发布时间】:2021-02-14 00:50:26
【问题描述】:
我正在使用 vuexfire 将我的 vue/vuex 应用程序连接到 Firebase Cloud Firestore。实际连接到 Firebase 时它工作正常。使用 Firebase 模拟器时它不起作用。
是否需要连接 Firebase 模拟器以允许 Vuexfire 连接的特定方式?
主要起作用的是
vue-cli-service serve
然后打开一个新的终端并运行
firebase emulators:start --import=./saved-data --export-on-exit
我将 firebase.json 中的设置更改为包含
"emulators": {
"firestore": {
"port": 8081
},
为了防止 firestore 模拟器和 vue-cli 开发服务器之间发生任何冲突。
但是控制台给了我这个错误:
Uncaught (in promise) FirebaseError:
false for 'get' @ L6
这里是 firebase 初始化:
firebase.initializeApp(firebaseConfig)
const auth = firebase.auth()
const db = firebase.firestore()
const func = firebase.functions()
const emulating = true
if (emulating) {
func.useEmulator('localhost', 5001)
//auth.useEmulator('http://localhost:9099/')
db.useEmulator('localhost', 8081)
}
以及(我认为)导致错误的 Vuex 代码:
bindProfile: firestoreAction(({ bindFirestoreRef, state }) => {
const pid = state.user.uid
console.log('Binding profile...')
return bindFirestoreRef('profile', db.collection('profiles').doc(pid))
}),
有没有人成功使用 Vuexfire 和 Firebase 模拟器?
谢谢!
【问题讨论】:
-
您是否尝试过使用default port for Firestore as specified on the docs:(Firestore 为 8080)?
-
模拟器的文档指定它可用from particular versions of the Client SDK(在特定的Web 情况下为firebase >= 8.0.0)。我看到vuexfire有以下对等依赖"firebase": ">=4.0.0".
-
我想知道这个要求是否会导致模拟器出现问题。让我知道更改端口并仔细遵循docs 是否可以解决问题。
-
交换端口没有帮助。我将 Firestore 模拟器切换回 8080,将 vue-cli 开发服务器端口切换到 8081(如果端口不可用,firebase 模拟器将无法启动)。当我更改
emulating = true并设置db.useEmulator('localhost', 8080)时,Vue 应用程序没有连接到任何 Firestore。还是一样的错误。 -
我也试过stackoverflow.com/questions/60536897/…描述的系统没有成功。
标签: javascript vue.js google-cloud-firestore firebase-tools vuexfire