简体   繁体   English

VueJS Firebase app导出默认错误的问题

[英]VueJS Firebase app problem of export default error

I'm trying to create crud app with vue 2 and firebase latest, & this is my firebase.js file我正在尝试使用 vue 2 和 firebase 最新创建 crud 应用程序,这是我的 firebase.js 文件

import firebase from 'firebase/app'
import 'firebase/auth'
import 'firebase/firestore'


const firebaseConfig = {
   stuff
  };

firebase.initializeApp(firebaseConfig);
const database = firebase.firestore()
const auth = firebase.auth()

const usersCollection = database.collection('users')

export{
 
    database,
    auth,
    usersCollection
}

and here is my store/index.js file这是我的 store/index.js 文件

import Vue from "vue";
import Vuex from "vuex";
import fb from "../../firebase"

import router from "../router";
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
   userProfile:{}
  },
  
  mutations: {
   
    setUserProfile(state,val)
    {
      state.userProfile=val
    },
    setPerformingRequest(state,val)
   {
     state.performingRequest=val
   }
  },
  actions: {

    async login({dispatch},form)
    {
      const{user} = await fb.auth().signInWithEmailAndPassword(form.email,form.password)
      dispatch('fetchUserProfile',user)
    },


    async signUp({dispatch},form)
    {

       const {user} = await fb.auth().createUserWithEmailAndPassword(form.email,form.password)

      //  create user object in userCollection

      await fb.usersCollection.doc(user.uid).set({
        firstName:form.firstName,
        middleName:form.middleName,
        lastName:form.lastName,
        email:form.email,
        password:form.password,
        gender:form.gender,
        age:form.user_age
      })

      dispatch('fetchUserProfile',user)

    },

    async fetchUserProfile({commit},user)
    {
      // fetching user profile data into constant named userProfile
      const userProfile = await fb.usersCollection.doc(user.uid).get()

      // setting the fetched data from firebase to state of userProfile
      commit('setUserProfile',userProfile.data())

      // now changing route to dashboard

      if(router.currentRoute.path ==='/')
      {
        router.push('/Dashboard')
      }

    },
  
    async logOut({commit})
    {
          
      // log user out
      await fb.auth.signOut()

      //  clear user data from state

      commit('setUserProfile',{})

      // changing route to homepage
      router.push('/')
    }



  },
  modules: {},
});

the application runs with warning in browser console Uncaught (in promise) TypeError: firebase__WEBPACK_IMPORTED_MODULE_4 _.default is undefined and in vs code terminal应用程序在浏览器控制台中运行时出现警告Uncaught (in promise) TypeError: firebase__WEBPACK_IMPORTED_MODULE_4 _.default is undefined and in vs code terminal
"export 'default' (imported as 'fb') was not found in '../../firebase' and “在'../../firebase'中找不到导出'default'(导入为'fb')
because of that neither user is getting registered nor the document is getting created因此,既没有用户注册,也没有创建文档
Does anyone know how to do this?有谁知道如何做到这一点?

Changing to更改为

const fb = require('../../firebase.js');

or to或者

import { auth, usersCollection } from "../../firebase";   

in the store file should do the trick.在商店文件中应该可以解决问题。


In the first case, you need to also change在第一种情况下,您还需要更改

await fb.auth().createUserWithEmailAndPassword

to

await fb.auth.createUserWithEmailAndPassword

In the second case, change在第二种情况下,改变

await fb.auth().createUserWithEmailAndPassword

to

await auth.createUserWithEmailAndPassword

In this case, also note that if you would use database in the store/index.js file you would need to import database as well, like:在这种情况下,还要注意,如果您要在store/index.js文件中使用database ,您还需要导入database ,例如:

import { database, auth, usersCollection } from "../../firebase"; 

More explanations here and here .更多解释herehere

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试导入错误:“firebase/app”不包含默认导出(导入为“firebase”) - Attempted import error: 'firebase/app' does not contain a default export (imported as 'firebase') "<i>Vue 2;<\/i> Vue 2;<\/b> <i>export &#39;default&#39; (imported as &#39;firebase&#39;) was not found in &#39;firebase\/app&#39;<\/i>在“firebase\/app”中找不到导出“默认”(导入为“firebase”)<\/b>" - Vue 2; export 'default' (imported as 'firebase') was not found in 'firebase/app' firebase function、Firebase 中的错误:没有创建 Z035489FF8D092741943E4A89 应用程序'DEFA'2 - error in firebase function, Firebase: No Firebase App '[DEFAULT]' has been created app.default.firebase 不是 function 错误 - app.default.firebase is not a function error 导入错误:“./App”不包含默认导出(导入为“App”) - import error: './App' does not contain a default export (imported as 'App') Firebase 带有 vuejs 的数据库:default.collection 不是 function - Firebase db with vuejs : default.collection is not a function 尝试导入错误:“./components”不包含默认导出(导入为“App”) - Attempted import error: './components' does not contain a default export (imported as 'App') 出现错误:没有要呈现的“App.js”的默认导出 - Getting error: No default export of 'App.js' to render 最新 @angular/fire 中的错误:Firebase:没有创建 Firebase 应用程序“[DEFAULT]” - 调用 Firebase App.initializeApp() - Error in latest @angular/fire: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() Firebase在子文件夹中的单页VueJS应用程序中重写 - Firebase rewrites in single page VueJS app in subfolder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM