-
先展示修改后可校验的完整 demo
html<template> <div class="rules-container"> <a-form-model ref="formRef" :model="formState" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol" > <a-form-model-item label="Activity name" prop="name"> <a-input v-model="formState.name" /> </a-form-model-item> <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }"> <a-button type="primary" @click="onSubmit">Create</a-button> </a-form-model-item> </a-form-model> </div> </template> <script> export default { name: 'Test', data() { return { formState: { name: '', }, rules: { name: [ { required: true, message: 'Please input Activity name', trigger: 'blur' } ] }, labelCol: { span: 4, }, wrapperCol: { span: 14, }, } }, methods: { onSubmit() { this.$refs.formRef.validate(valid => { if(valid) { console.log('values'); } else{ console.log('error submit!!') return false } }) } } } </script> -
官网:校验生效前提

-
重点

【Ant Design Vue】表单校验 rules 不起作用
May21☀️2024-11-29 9:47
相关推荐
广州灵眸科技有限公司19 小时前
瑞芯微RV1126B开发板(EASY-EAI-PI2) Easy-Eai编译环境准备与更新万少20 小时前
我把 Kimi 接进微信,几分钟做了个随手出图助手xiaofeichaichai20 小时前
网络请求与实时通道kTR2hD1qb20 小时前
从 Responses API 到 Chat Completions:一个模型网关的设计复盘kyriewen1 天前
浏览器缓存最强攻略:强缓存、协商缓存、CDN、更新策略,一篇搞定持敬chijing1 天前
Web渗透之SQL注入-联合查询注入-注入点数据类型判断卷帘依旧1 天前
Web3前端一面古韵1 天前
告别手写分页逻辑:usePagination 从 50 行到 3 行小村儿1 天前
连载12- Cluade code 的MCP 到底还用不用