VUE Props验证器如何设置默认值,如果不通过验证器
是否有一种方法可以将默认值设置为使用验证器,如果当前道具不通过验证器,我想将值设置为1,如果该值小于3,这里是一个景象。
currentStep: {
type : Number,
required : true,
validator : (value) => {
return value <= 3;
},
default : 1
}
Is there a way to set a default value to a prop with validator if the current prop dont pass the validator, i want to set the value to 1 if it is less than 3, here a exemple.
currentStep: {
type : Number,
required : true,
validator : (value) => {
return value <= 3;
},
default : 1
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
验证器
方法始终返回布尔值,它不用于返回任何其他值,您可以根据道具使用计算的属性并验证它:The
validator
method always returns a boolean value, it's not used to return any other value, you could use a computed property based on the prop and validate it :