我是Vue.js的新手,我正在尝试将Firebase与Vue.js应用程序集成在此应用程序中,我有两个字段,我想将它们存储到Firebase的数据库中,但是它提供了我的错误:-
<template>
<div class="container">
<div class= "row">
<div class= "col-xs-12 co-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3">
<h1>Http</h1>
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" v-model="username">
</div>
<div class="form-group">
<label>Mail</label>
<input type="text" class="form-control" v-model="email">
</div>
<button class="btn btn-primary" @click="submit">Submit</button>
</div>
</div>
</div>
</template>
<script>
import firebase from 'firebase'
var config = {
apiKey: "AIzaSyAQoOXm69M5WKRjRL_ee4wkh4Bbp7mSF3E",
authDomain: "vuejs-http-11c9f.firebaseapp.com",
databaseURL: "https://vuejs-http-11c9f.firebaseio.com",
projectId: "vuejs-http-11c9f",
storageBucket: "vuejs-http-11c9f.appspot.com",
messagingSenderId: "messenger_id"
};
firebase.initializeApp(config);
export default {
data() {
return{
username:'',
email:''
};
methods:{
submit(){
firebase.createUser(this.username, this.email)
.then((result) => {
console.log(result);
}).catch((err) => {
console.log(err)
});
}
}
}
单击提交按钮时遇到的错误是
未捕获的TypeError:__WEBPACK_IMPORTED_MODULE_0_firebase ___ default.a.createUser不是函数
我将如何解决此错误?
答案 0 :(得分:0)
我认为在您的Submit方法上,您缺少.auth()
。您的Submit方法应如下所示:
firebase.auth().createUserWithEmailAndPassword(this.username, this.email)
.then((result) => {
console.log(result);
}).catch((err) => {
console.log(err)
});
}