I am using Vue 3 and vee-validate and yup schema to validate a form before sending the post request and it's working ok, but my problem is when the response comes from the server, for example, a duplicated email, I am struggling to validate the errors. If i do this:
form.value.setErrors({
email: 'my error message'
});
it works ok!
but i want to loop in my array of errors to see the fields(param) and the error messages(msg) but i can’t define the param as i do her:
for (const error of errors.response.data.errors) {
let param = error.param;
let msg = error.msg;
form.value.setErrors({
param: msg
});
}
What i expect is loop in my “errors.response.data.errors” and setErrors () with-param and msg variables
Computed property names feature was introduced in ECMAScript 2015 (ES6) that allows you to dynamically compute the names of the object properties in JavaScript object literal notation.
i had to use [param]:msg