我有一个简单的登录表单,如果用户使用错误的密码或用户名,我会显示一条消息
JS
onSignin() {
axios.post(
'api/user/signin',
{
email: this.email,
password: this.password,
},
{
headers: { 'X-Requested-With': 'XMLHttpRequest' },
},
).then((response) => {
this.$router.push('dashboard');
}).catch((error) => {
this.errors.add('credentials', 'Wrong user or Password'); //this message i want to move to the dictionary
});
},
HTML
<form action="POST" >
<span v-show="errors.has('credentials')" class="help is-danger">{{ errors.first('credentials') }}</span>
<p class="form-group">
...
这样可以显示错误消息,但是如何将此消息添加到字典中,我将所有消息都放在一个地方?
答案 0 :(得分:0)
我在那里得到了答案;)
Validator.dictionary.merge({
en: {
messages: {
credentials: 'Wrong user or password'
}
}
});
const message = this.$validator.dictionary.getMessage('en', 'credentials');
this.errors.add('credentials', message); //this message i want to move to the dictionary