由于需要验证数字,我在rules中加入type为number,然后输入数字时提示 is not a number
好吧,我用正则判断,去掉type:number 验证成功,代码执行通过
后来, 由于后端返回的为数字,验证又提示 is not a string
提问,如何能让他不去验证格式呢。
<el-form-item label="价格" prop="price"> <el-input v-model="form.price" ></el-input> </el-form-item>
<el-form-item label="克重" prop="weight" > <el-input v-model="form.weight" type="number"></el-input> </el-form-item>
<el-form-item label="汇率" prop="rate"> <el-input v-model="form.rate" type="number"></el-input> </el-form-item>
rules: {
name: [
{ required: true, message: '请填写名称', trigger: 'blur' }
],
price: [
{ required: true, message: '请填写价格', trigger: 'blur' }
],
weight: [
{ required: true, message: '请填写克重', trigger: 'blur' },
{validator(r,v,b){console.log(v);(/^[\d]*$/).test(v)?b():b(new Error('请填写数字'))}}
],
rate: [
{ required: true, message: '请填写数字汇率', trigger: 'blur'},
{validator(r,v,b){(/^[\d]*$/).test(v)?b():b(new Error('请填写数字'))}}
]
}
我也研究了半天。。原因出在trigger: 'blur',一张图说明: