运行Vue-CLI应用程序时初始化Firebase时出错

时间:2018-09-17 15:26:03

标签: firebase webpack vue-cli

我对Vue-CLI和Firebase很陌生。我一直在使用Firebase进行授权和使用Firestore DB。尝试在浏览器中呈现应用程序时遇到了以下错误:

Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_3_firebase___default.a.auth is not a function

从我的外观看,我初始化Firebase的方式似乎有问题,但是我找不到问题。

这是我的main.js文件:

import Vue from 'vue'
import App from './App'
import router from './router'
import firebase from 'firebase'
import 'firebase/firestore'

Vue.config.productionTip = false

let app
let fireBaseConfig = {
    apiKey: ***,
    authDomain: ***,
    databaseURL: ***,
    projectId: ***,
    storageBucket: ***,
    messagingSenderId: ***
  };

firebase.initializeApp(fireBaseConfig)

firebase.auth().onAuthStateChanged(function(user){
  if(!app){
    /* eslint-disable no-new */
    app = new Vue({
      el: '#app',
      router,
      components: { App },
      template: '<App/>'
    })
 }
   });

const firestore = firebase.firestore();
  const settings = {/* your settings... */ timestampsInSnapshots: true};
  firestore.settings(settings);

export { firestore }

0 个答案:

没有答案