我正在使用 firebase 使用户登录,但控制台提示未定义 firebase。 我正在导入,firebase,我根据 firebase 给你的文档正确设置了我的配置,但仍然没有成功。
import Vue from 'vue'
import App from './App.vue'
import VeeValidate from 'vee-validate';
import router from './router';
import firebase from 'firebase';
Vue.use(VeeValidate);
Vue.config.productionTip = false
// Initialize Firebase
var config = {
apiKey: "<my api key>",
authDomain: "<my auth domain>",
databaseURL: "<my database url>",
projectId: "todo-bb5d3",
storageBucket: "",
messagingSenderId: "638496899966"
};
firebase.initializeApp(config);
new Vue({
router,
render: h => h(App)
}).$mount('#app')
导致问题的文件:
<template>
<div class="LogIn">
<h3>Sign Up</h3>
<input type="email" v-model="email" placeholder="email" name="" value="">
<input type="passeord" v-model="password" placeholder="password" name="" value="">
<button v-on:click="signUp" type="button" name="button">Sign Up</button>
</div>
</template>
<script>
export default{
name: 'LogIn',
data: function() {
return{
email: '',
password: ''
}
},
methods: {
signUp: function(){
firebase.auth().createUserWithEmailAndPassword(this.email, this.password).then(
function(user){
alert('Your account has been created')
},
function(err) {
alert('Opps! ' + err.message)
}
)
}
}
}
</script>
最佳答案
您必须在“导致问题的文件”中导入 firebase。
import firebase from 'firebase';
在此处粘贴您的 api key 也不是一个好主意,即使是测试应用程序,我建议您编辑您的帖子并对其进行编辑。
关于javascript - 'firebase' 未定义 - Vue.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50912966/