vuelidate:验证依赖于其值的项目列表

vuelidate: validate items list that depend on its values

我需要验证与元素本身的值相关的列表元素。

我是否可以或应该为每个产品创建验证?

new Vue({
    el: "#app",
  data: {
    text: '',
    sons: [
      {amount: 20, pending: 50}, 
      {amount: 30, pending: 150}
    ]
  },
  validations: {
    text: {
      required,
      minLength: minLength(5)
    },
    sons: {
      minLength: 3,
      $each: {
        amount: {
          maxValue: maxValue(this.sons[x].pending) // how to set x?
        }
      }
    }
  }
})

https://jsfiddle.net/e0tL4yph/

在 Vuelta 存储库中,我发布了这个问题,答案是:

In that case you want to use the second argument of validation function.

amount: {
  ltePending: (amount, { pending }) => amount <= pending
}

如我所愿!