dha什么牌子好
iView——表单校验是否为空填坑
最近转岗去做了vue开发,然后使⽤的UI框架是iView,总体来说iView,elementUI都差不多,内容丰富使⽤⽅便,可是可是挖的坑也不少,尤其是有些功能的使⽤⽅法介绍不全,⼀笔带过,需要⾃⼰摸索,这不,最近遇到⼀个匪夷所思的问题。
⼤家都知道表单校验中最基本的⼀条就是是否为空的校验。这个官⽹给出了例⼦,我们来看下:
qq怎么设置密保ruleValidate: {
name: [
{required: true, message: 'The name cannot be empty', trigger: 'blur'}
],
高利贷合同mail: [
{required: true, message: 'Mailbox cannot be empty', trigger: 'blur'},
凤凰古城门票多少钱{type: 'email', message: 'Incorrect email format', trigger: 'blur'}
],
city: [
{required: true, message: 'Plea lect the city', trigger: 'change'}
],
gender: [
{required: true, message: 'Plea lect gender', trigger: 'change'}
],
interest: [
{required: true, type: 'array', min: 1, message: 'Choo at least one hobby', trigger: 'change'},
{type: 'array', max: 2, message: 'Choo two hobbies at best', trigger: 'change'}
],
date: [
{required: true, type: 'date', message: 'Plea lect the date', trigger: 'change'}
],
time: [
{required: true, type: 'string', message: 'Plea lect time', trigger: 'change'}
],
desc: [
{required: true, message: 'Plea enter a personal introduction', trigger: 'blur'},
{type: 'string', min: 20, message: 'Introduce no less than 20 words', trigger: 'blur'}
]
}
还算挺清晰的哈,别着急,请听我的问题,如果input⾥⾯输⼊的是数字,⽽且校验类型type=number,你猜input的value的类型是什么,如果说是number,那你就太天真了,⿁知道经历了什么,iView给出的结果是string,所以当⼤家在校验数字是否为空的时候,即使输⼊了内容,也还是会报xxx不能为空的错误,怎么解决呢,也简单,官⽅出错了,我⾃⼰写⼀套不就⾏了吗,嘿嘿,看代码。
const isEmpty = (rule, value, callback) => {
if (value == null || value == undefined || value == "") {
微信唯美头像callback(new Error('价格不能为空!'))
赞成的反义词吧字组词} el {
callback();
}
};
ruleValidate: {
baPrice: [
白色面板
{required: true, message: '基础价格不能为空!', trigger: 'blur', type: 'number', validator: isEmpty},
],
},
其他坑请看后续更新~