antd 表单验证报错
程序员文章站
2022-04-04 16:03:28
...
编辑表单信息,初始化“价格”字段是个number类型,表单中“价格”字段,失去焦点是验证没问题,提交表单时验证不通过
<a-form-item label="物料价格" class="relative" ref="nPrice" name="nPrice" required>
<a-input
class="commonInput"
type="number"
v-model:value="formState.nPrice"
placeholder="请输入物料价格"
></a-input>
<span class="unit">/500g</span>
</a-form-item>
// 表单验证规则
const rules = {
nMaterialName: [
{ required: true, message: "请输入物料名称", trigger: "blur" }
],
nCategoryId: [
{ required: true, message: "请选择物料类别", trigger: "change" }
],
nRarity: [
{ required: true, message: "请选择稀缺性", trigger: "change" }
],
nPrice: [
{
required: true,
message: "请输入物料价格",
trigger: "change",
type: "number"
}
]
};
主要设置验证规则 type: “number”
formRef.value
.validate()
.then(() => {
});
下一篇: 直角坐标系点的旋转