我不想尝试将道具传递给<b-modal>
按钮,所以我只想在单击默认的OK按钮时在我的模态中调用signinUser()
@click
,但是我的模态似乎不对此射击。
尽管signinUser()
将在@hidden
上触发。
我还试图阻止模式消失,除非对用户进行身份验证(这就是为什么我不希望它在@hidden
上触发)
有人可以指出正确的方向吗?
这是我在使用firebase进行身份验证的组件:
<template>
<div class="container">
<b-modal id="signinModal" @click="signinUser($event)" v-model="modalShow" :no-close-on-backdrop="true">
<input id="email" v-model="email" placeholder="email">
<input id="pass" v-model="password" placeholder="password">
</b-modal>
<form v-on:submit.prevent class="cube" v-if="modalShow == false">
<div>
<input id="title" v-model="title" placeholder="title">
</div>
<div>
<textarea id="body" v-model="body" placeholder="body"></textarea>
</div>
<div>
<b-button id ="postbtn" @click="addpost($event)" variant="outline-success">Publish</b-button>
</div>
</form>
</div>
</template>
<script>
const { fb, db } = require('../../fireconfig.js')
export default {
name: 'AddPost',
data: function() {
return {
title: '',
body: '',
modalShow: true,
email: '',
password: ''
}
},
methods: {
signinUser(e) {
e.preventDefault()
fb.auth().signInWithEmailAndPassword(this.email, this.password)
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === 'auth/wrong-password' || errorCode === 'auth/invalid-email') {
alert('password or email incorrect', errorCode, errorMessage);
//do nothing an modal stays up
} else {
console.log('user successfully authenticated')
this.modalShow = false
}
});
},
}
}
</script>
使用@ok
代替@click
:
<b-modal id="signinModal" @ok="signinUser($event)" v-model="modalShow" :no-close-on-backdrop="true">
<!-- more code -->
</b-modal>