<el-form ref="dataForm" :rules="rules" :model="dataForm" label-width="100px">
<el-form-item label="年龄" prop="infoList.age">
<el-input v-model="dataForm.infoList.age" type="text" />
</el-form-item>
</el-form>
<script>
export default {
data() {
const valiNonnegative = (rule, value, callback) => { // 非负数
const reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/
if (!reg.test(value)) {
callback(new Error('请输入非负数'))
} else {
callback()
}
};
return {
dataForm: {
infoList: {
age:''
}
},
rules: {
'infoList.age': { validator: valiNonnegative , trigger: 'blur' }
}
};
}
原本出错的地方 如下:
来源:CSDN
作者:路痴不脸盲
链接:https://blog.csdn.net/shulan5/article/details/103810317