0

我有一个简单的登录表单,如果用户使用错误的密码或用户名,我会显示一条消息

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">
    ...

这有效,错误消息被显示,但我如何将此消息添加到字典中,我将所有消息都放在一个地方?

4

1 回答 1

0

我在那里得到了答案;)

https://github.com/baianat/vee-validate/issues/963

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
于 2017-11-09T19:58:07.283 回答