是否可以将自定义错误添加到ErrorBag中
我正在使用nuxtjs。我已经通过nuxt.config.js将vee-validate注册到了我的插件中
它工作正常但是
我想在模板中使用相同的错误代码
例如:
<template>
<div v-if="errors.all().length>0">
//loop through
</div>
</template>
我正在使用axios来获取用户信息。
如果请求未返回我的预期数据集。我以为我可以
this.errors.push('this is my error message') //-> or some variant of this
当我这样做时,我得到this.errors.push不是一个函数
我知道
this.errors = ErrorBag{ __ob__: Observer} //-> has items and a vmId attributes
如果我修改代码以推送到ErrorBag上,则会得到未定义的推送
最佳答案
它记录在ErrorBag的API中。您可以添加自定义消息,例如:
// For example, you may want to add an error related to authentication:
errors.add({
field: 'auth',
msg: 'Wrong Credentials'
});
在此处查看文档以获取更多信息:https://baianat.github.io/vee-validate/api/errorbag.html#api
关于vue.js - 将自定义错误添加到vee验证器(ErrorBag),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55385134/