【问题标题】:Vee validate in dynamic element动态元素中的 Vee 验证
【发布时间】:2018-05-21 12:36:54
【问题描述】:

Vee Validate dynamic element with custom message in common error box.

如果存在验证错误,我需要在页面顶部单独显示错误消息并在输入字段上显示突出显示。如何检查组件中发生的任何验证错误。

我想将它创建为一个组件,保存按钮在主页上,并在保存之前验证每个组件。

<div>Need to show the error mesage here.</div>
<div id="product">
 <dl v-for="(items, index) in configurations">
     {{items.assemblyconfigurationname}}
     <input type="text" :name="'assemblyconfigurationvalue_' + index" 
         v-validate="'required'" :class="[{ error_input: errors.has('assemblyconfigurationvalue_' + index)}]" v-model="items.assemblyconfigurationvalue">
</dl>

【问题讨论】:

    标签: vue.js vee-validate


    【解决方案1】:

    您可以在第一个 div 中添加另一个循环:

    Vue.use(VeeValidate)
    new Vue({
    el: "#app",
      data: {
          configurations: [
          	{ assemblyconfigurationname: "name1", assemblyconfigurationvalue: 'value1' },
            { assemblyconfigurationname: "name2", assemblyconfigurationvalue: 'value2' }
          ]
      }
    })
    .error {
      color: red;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.min.js"></script>
    <script src="https://unpkg.com/vee-validate@2.0.0-beta.25"></script>
    
    <div id="app">
      <div v-for="(items, index) in configurations" class='error'>{{ errors.first('assemblyconfigurationvalue_' + index) }}</div>
      <div id="product">
        <dl v-for="(items, index) in configurations">
          {{items.assemblyconfigurationname}}
          <input type="text" :name="'assemblyconfigurationvalue_' + index" 
                 v-validate="'required'" :class="[{ error_input: errors.has('assemblyconfigurationvalue_' + index)}]" v-model="items.assemblyconfigurationvalue">
        </dl>
      </div>
    </div>

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 2020-12-20
      • 1970-01-01
      • 1970-01-01
      • 2018-03-01
      • 1970-01-01
      • 2014-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多