vue3 行内校验规则 rules validate校验
【代码】vue3 行内校验规则 rules validate校验。
·
const form2 = ref()
function doSave() {
loading.value = true;
form2.value.validate((valid: any) => {
if (valid) {
httpPost({ method: "project.save", form: form.value }).then((res: any) => {
emit("afterSave", "");
if (res.status == 200) {
alert(res.msg);
}
loading.value = false;
}).catch(() => {
loading.value = false;
});
} else {
alert("请按提示完善表单项目")
loading.value = false;
}
})
}
<el-form ref="form2" :model="form" label-width="80px">
<el-form-item label="名称" prop="名称" required
:rules="[{ required: true, message: '此项不能为空', trigger: 'blur' }]">
<el-input autoComplete="off" v-model="form.名称" clearable placeholder="请输入名称" />
</el-form-item>
<el-button :loading="loading" type="primary" @click="doSave">
<span v-if="!loading"> 保 存 </span>
<span v-else>提 交 中...</span>
</el-button>
</el-form>
更多推荐
已为社区贡献1条内容
所有评论(0)