简体   繁体   English

Vee-validade vue3 setErrors 无法定义字段

[英]Vee-validade vue3 setErrors can't define filed

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.我正在使用 Vue 3 和 vee-validate 和 yup 模式在发送发布请求之前验证表单并且它工作正常,但我的问题是当响应来自服务器时,例如,重复的 email,我正在努力验证错误。 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:但我想在我的错误数组中循环查看字段(参数)和错误消息(msg),但我不能像我那样定义参数:

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我期望的是在我的“errors.response.data.errors”和 setErrors () with-param 和 msg 变量中循环

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. ECMAScript 2015 (ES6) 中引入了计算属性名称功能,它允许您动态计算 JavaScript object 文字符号中的 object 属性的名称。

i had to use [param]:msg我不得不使用 [param]:msg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM