【发布时间】:2021-05-08 03:04:31
【问题描述】:
知道为什么我的 { auth } 函数“不是函数”但我的 { db } 函数工作得很好吗?示例文件如下。
我在尝试调用 login() 方法时遇到的错误是
[Vue warn]: Error in created hook: "TypeError: _firebase__WEBPACK_IMPORTED_MODULE_2__.auth.auth is not a function"
使用 Vue 2 并通过 npm install firebase --save 安装 firebase。
src/firebase.js
import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';
const firebaseConfig = {
apiKey: 'xx',
authDomain: 'xx',
databaseURL: 'xx',
projectId: 'xx',
storageBucket: 'xx',
messagingSenderId: 'xx',
appId: 'xx',
measurementId: 'xx',
};
firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();
const auth = firebase.auth();
export { db, auth };
login.vue
import { auth } from '@/firebase';
login() {
try {
auth
.auth()
.signInWithEmailAndPassword(this.email, this.password)
.then(() => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
} catch (error) {
console.log(error);
}
},
文档中的示例代码,运行良好
import { db } from '@/firebase';
var docRef = db.collection("cities").doc("SF");
docRef.get().then((doc) => {
if (doc.exists) {
console.log("Document data:", doc.data());
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
}).catch((error) => {
console.log("Error getting document:", error);
});
【问题讨论】:
标签: javascript firebase vue.js authentication