<template>
<div>
...
<el-form :model=formData :rules=rules>
<el-form-item prop='name'>
<template #label>
<span>*</span>姓名
</template>
<el-input class="required-star" v-model='formData.name'></el-input>
</el-form-item>
</el-form>
</div>
</template>
<script>
export default{
data(){
return {
formData:{
name:'',
......
},
rules:{
name:[
{
validattor:(rule,value,callback)=>{
if(满足条件){
callback()
}else{
callback(new Error('校验失败提示'))
}
}
}
]
}
}
}
}
</script>
<style lang='scss' scoped>
.el-form{
.required-star{
color: #f56c6c;
margin-right: 5px;
}
}
</style>
form表单自定义校验规则并显示红色星标
于 2024-09-09 14:44:48 首次发布