vue.js - 在 Vue 3 中登录/检索文档 Firebase 后路由到不同页面时出错
问题描述
我使用 Vuex 4 和 Firebase 开始了一个新的 Vue 3 项目。我想尝试 Firebase 和 Vue 3(还没有使用 composition-api),但我想我一定是在某个地方遗漏了一些东西。
我正在通过 Firebase 电子邮件/密码身份验证处理注册/输入/退出表单,但是在登录和检索用户详细信息时,我一直遇到一个错误,该错误会破坏导航到不同的页面。起初我认为这与 Vuex 4 有关,但是当将代码作为常规方法移动到登录组件时,我得到了同样的错误(完全跳过 Vuex 来测试这个)。
登录实际上有效(我获取了用户数据)并检索了配置文件数据也有效,但是一旦我尝试重定向,我就会收到此错误:
[Vue warn]: Unhandled error during execution of scheduler flush. This is likely a Vue internals bug. Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/vue-next
at <Home onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< null > >
at <RouterView>
at <App> build.umd.js:2420
Uncaught (in promise) TypeError: parent is null - runtime-dom.esm-bundler.js:11
登录方式:
login() {
// this.$store.dispatch('login', {
// email: this.loginForm.email,
// password: this.loginForm.password
// }).then(() => this.$router.push('/dashboard'))
fb.auth.signInWithEmailAndPassword(this.loginForm.email, this.loginForm.password)
.then((userCredential) => {
const user = userCredential.user;
if (user && user.uid) {
const ref = fb.usersCollection.doc(user.uid);
ref.get().then((doc) => {
if (doc.exists) {
// TODO save in vuex store
console.log(doc.data());
this.$router.push('/')
} else {
alert("No such document!");
}
});
}
})
.catch((error) => {
alert(error.message);
});
},
当我离开this.$router.push('/')
(并doc.data()
包含我需要的数据)时不会发生错误,但我需要在登录后将用户重定向到他的仪表板。
有谁知道如何解决这个问题?一定是我忽略的简单事情。
我在组件 ( ) 中导入以下文件import * as fb from "@/firebase";
:
/* eslint-disable */
import firebase from 'firebase/app';
import 'firebase/auth'
import 'firebase/firestore'
// firebase init
const firebaseConfig = {
apiKey: "X",
authDomain: "X.firebaseapp.com",
projectId: "X",
storageBucket: "X.appspot.com",
messagingSenderId: "123",
appId: "X",
measurementId: "X"
}
firebase.initializeApp(firebaseConfig)
// utils
const db = firebase.firestore()
const auth = firebase.auth()
// collection references
const usersCollection = db.collection('users')
// export utils/refs
export {
db,
auth,
usersCollection,
}
由于 API 信用,不想在网上发布演示项目,但如果需要,请告诉我,我会看看我能做什么
解决方案
推荐阅读
- unity3d - 反正有没有改变统一代码中插入符号的宽度?
- python - 如何通过 Python 中的 Selenium 导航到下一页?
- javascript - 使用自定义 CSS 抛出我自己的验证消息 | 网址验证
- asp.net-core - 如何将 .NET Core [IServiceProvider] 本身注入服务?
- c++ - 智能感知不在 qml 中显示属性和附加属性的信号
- c++ - 提升错误(分段错误) simple_segregated_storage.hpp
- python - SQLite + Python 数据未保存在数据库文件中
- python - jQuery/Django 检索文件
- reactjs - 仅在一项上设置状态
- javascript - 无法在 TinyMCE 中上传文件...?