【问题标题】:Validating a non-existent field error in console在控制台中验证不存在的字段错误
【发布时间】:2020-04-28 23:56:23
【问题描述】:

我的问题是当我尝试在我的系统上使用 VeeValidate 验证我的字段时收到此错误。

Uncaught (in promise) Error: [vee-validate] Validating a non-existent field: "". Use "attach()" first.
    at createError (vee-validate.esm.js?00d1:297)
    at Validator._handleFieldNotFound (vee-validate.esm.js?00d1:2282)
    at Validator.validate (vee-validate.esm.js?00d1:1959)
    at ScopedValidator.validate (vee-validate.esm.js?00d1:3276)
    at VueComponent.next (QueryAcademicForm.vue?f0b2:332)
    at click (eval at ./node_modules/vue-loader/lib/template-compiler/index.js?{"id":"data-v-e5b3dc5a","hasScoped":false,"transformToRequire":{"video":["src","poster"],"source":"src","img":"src","image":"xlink:href"},"buble":{"transforms":{}}}!./node_modules/vue-loader/lib/selector.js?type=template&index=0!./src/components/QueryAcademicForm.vue (0.3f605440c8faec0820bd.hot-update.js:22), <anonymous>:364:25)
    at invoker (vue.esm.js?efeb:2027)
    at HTMLButtonElement.fn._withTask.fn._withTask (vue.esm.js?efeb:1826)

我试图复制它here on jsfiddle,它给了我同样的错误,但错误信息有一点点不同

Uncaught (in promise) Error: [vee-validate] Validating a non-existent field: "result". Use "attach()" first.
    at Re (vee-validate.min.js:1)
    at vn._handleFieldNotFound (vee-validate.min.js:1)
    at vn.validate (vee-validate.min.js:1)
    at ln.validate (vee-validate.min.js:1)
    at a.validateBeforeSubmit ((index):355)
    at click (eval at $a (vue.min.js:6), <anonymous>:2:4043)
    at t (vue.min.js:6)
    at HTMLButtonElement.Ir.t._withTask.i._withTask (vue.min.js:6)

需要注意的一点是,错误并非出现在 form-input 组件的每个实例上,而仅出现在最后一步。

【问题讨论】:

    标签: vue.js vue-component


    【解决方案1】:

    由于 Vue.js 使用的“就地补丁”策略而出现此问题。这种情况在VeeValidate documentation 中有描述。基本上,您需要通过为每个输入元素的 key 属性设置唯一值来告诉 Vue.js 分别跟踪所有子组件:

    <form-input key="unique"></form-input>
    

    这是一个有效的JSFiddle 示例。

    【讨论】:

    【解决方案2】:

    在我的情况下,它确实出现了,因为我的 HTML 基于特定条件动态呈现,并且我使用这段代码 &lt;div v-if="condition"... &gt; 进行动态呈现。尽管我使用的是唯一键。

    为了解决这个问题,我将v-if 更改为v-show 就像这样&lt;div v-show="condition"... &gt; 并且错误消失了。

    Reference

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-26
      • 2016-10-24
      相关资源
      最近更新 更多