【问题标题】:Vuelidate vue.js latest for vue3 using the helpers.forEach approach for array of objectsVuelidate vue.js 最新的 vue3 使用 helpers.forEach 方法处理对象数组
【发布时间】:2021-09-05 17:06:55
【问题描述】:

对 vue3 使用最新的 Vuelidate vue.js,对对象数组使用 helpers.forEach 方法。我尝试运行表单,但验证导致错误如下所示

给出 $response.$errors 在控制台中未定义 Uncaught (in promise) TypeError: $response.$errors is undefined

export default {
  setup () {
    const rules = {
      collection: {
        $each: helpers.forEach({
          name: {
            required
          }
        })
      }
    }
    const state = reactive({
      collection: [
        { name: '' },
      ]
    })
    const v = useVuelidate(rules, state)
    return { v, state }
}
}

这是代码的模板

  <div
    v-for="(input, index) in state.collection"
    :key="index"
    :class="{
        error: v$.collection.$each.$response.$errors[index].name.length,
      }"
  >
    <input v-model="input.name" type="text" />
    <div
      v-for="error in v$.collection.$each.$response.$errors[index].name"
      :key="error"
    >
      {{ error.$message }}
    </div>
  </div>
</template>

【问题讨论】:

    标签: vuejs3 vuelidate


    【解决方案1】:

    有点晚了,但在您的模板中,您指的是v$.collection 而不是v.collection。在您的设置中,您返回的是 v 而不是 v$

    【讨论】:

      猜你喜欢
      • 2021-05-29
      • 2018-01-25
      • 1970-01-01
      • 2021-05-28
      • 1970-01-01
      • 2021-12-27
      • 2019-06-06
      • 2020-09-24
      • 1970-01-01
      相关资源
      最近更新 更多