gpt4 book ai didi

vue.js - vuelidate:验证依赖于其值的项目列表

转载 作者:搜寻专家 更新时间:2023-10-30 22:28:35 26 4
gpt4 key购买 nike

我需要根据元素本身的值来验证列表的元素。

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

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
}

它如我所愿!

关于vue.js - vuelidate:验证依赖于其值的项目列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47637107/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com