gpt4 book ai didi

javascript - 无法创建全局 vue 变量(Vue.prototype.$firebase)

转载 作者:行者123 更新时间:2023-11-30 19:20:41 24 4
gpt4 key购买 nike

我在 login.vue 中提交表单,它将调用 submit()。然后我在 Web 控制台中遇到以下错误。

Uncaught TypeError: Cannot read property 'auth' of undefined

ma​​in.js

import Vue from 'vue'
import App from './App'
import router from './router'
import * as firebase from 'firebase/app'
import { firebaseConfig } from '@/firebaseConfig';

Vue.prototype.$firebase = firebase.initializeApp(firebaseConfig)
Vue.config.productionTip = false

new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})

登录.vue

const authService = {
methods: {
submit () {
this.$firebase.auth().signInWithEmailAndPassword(this.login.email, this.login.pass).then(
(user) =>{
this.$router.replace('bm')
}
)
}
}
}

最佳答案

您还必须:

import 'firebase/auth'

firebase/app 导入之后以获得 Firebase Auth 产品功能。

关于javascript - 无法创建全局 vue 变量(Vue.prototype.$firebase),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57514449/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com