D
D
Darkhan Kamaliev2019-09-18 14:35:29
Vue.js
Darkhan Kamaliev, 2019-09-18 14:35:29

How to display (handle) errors in vue.js that came from the laravel validator?

Good afternoon, tell me how to correctly display validator errors in vue.js in the notify plugin.

.catch(error => {
                        this.$q.loading.hide()
                        this.$q.notify({
                            color: 'red-4',
                            textColor: 'white',
                            message: 'Ошибка'
                        })
                    })

Now it looks like this, but does not give specifics. Of course, you can manually start writing if to each field, but it looks like a monkey's work. How it is possible to implement dropout of errors? How to process an array coming from Laravel? For example, the validator returned errors for 3 fields and 3 notify responses were displayed, I don’t understand how to iterate over such an array.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin B., 2019-09-18
@darakanoit

.catch((error) => {
        let errors = error.response.data.errors;
        for (let variable in errors) {
            this.$notify({
                type: 'error',
                title: errors[variable][0],
            });
        continue;
    }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question