VUE项目开发实践——Element ui 和Mint ui表单验证*必填
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
免费下载资源
·
//js控制不了时就写在行内控制
<el-form-item class="el-select-class" label="教师姓名" :rules="[{ required: true, message: '教师姓名不能为空'}]" >
<el-select v-model="newClassForm.UserId" placeholder="请选择教师姓名">
<el-option v-for="item in selectTeachers" :key="item.UserId" :label="item.RealName" :value="item.UserId">
</el-option>
</el-select>
</el-form-item>
//教师验证
newClassFormRules: {
UserId: [{
required: true,
message: '请输入教师姓名',
trigger: 'change'
}]
}
//更新:发现之前是错误的,没研究透彻:type:Number/String/Array/Function/Booleans ,trigger:'blur,change';
popForm: {
Citys: ''
},
popFormRules: {
Name: [{
required: true,
message: '请输入机构名称',
trigger: 'blur,change'
}, {
min: 1,
max: 15,
message: '长度在 1到15个字',
trigger: 'blur'
}],
Citys: [{
type: 'array,string',
required: true,
message: '请选择地区',
trigger: 'change'
}],
PhoneNumber: [{
required: true,
validator: updatePhone,
trigger: "blur"
}]
};
var updatePhone = (rule, value, callback) => {
let editForm = this.editForm;
if(!value) {
return callback(new Error("手机号不能为空"));
};
setTimeout(() => {
watch~if(!Number(value)) {
callback(new Error("请输入数字值"));
} else {
if(value.length !== 11) {
callback(new Error("手机号是11位"));
} else {
this.$http.get("/rc_teahcer/checkxxxx",{
params:{
PhoneNumber: value,
Id: editForm.Id
}
}).then(res => {
if(
res.data == true) {callback();
} else {
callback(new Error("该用户已存在!"));
}
});
}}}, 1000);};
//如果还一直验证不通过,需要数据类型转换:数字转字符串
GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45
7 个月前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 7 个月前
更多推荐
已为社区贡献1条内容
所有评论(0)