【发布时间】: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>
【问题讨论】: