若依前端分离版-APP(UNI APP)表单添加验证

1.在page页面中onReady事件添加如下代码

复制代码
		onReady() {
			this.$refs.form.setRules(this.rules)
		},

2.在data中添加ruels这个对象

复制代码
				rules: {
					nickName: {
						rules: [{
							required: true,
							errorMessage: '用户昵称不能为空'
						}]
					},
					phonenumber: {
						rules: [{
							required: true,
							errorMessage: '手机号码不能为空'
						}, {
							pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
							errorMessage: '请输入正确的手机号码'
						}]
					},
					email: {
						rules: [{
							required: true,
							errorMessage: '邮箱地址不能为空'
						}, {
							format: 'email',
							errorMessage: '请输入正确的邮箱地址'
						}]
					}
				},
复制代码
			/** 提交按钮 保存报工按钮 */
			submitForm(ref) {
				console.log("保存调度派工开始")
				this.$refs.form.validate().then(res => {
						if (this.repair.repairId != null) {
							updateRepair(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.open = false;
								this.getList();

							});
						} else {
							addRepair(this.repair).then(response => {
								this.$modal.msgSuccess("新增成功");
								this.open = false;
							});
						}
					}
				);
				console.log("保存调度派工结束")
			},

注:得到用户存储的帐号和密码

复制代码
		userName: this.$store.state.user.name,
相关推荐
掘金安东尼3 小时前
纯 CSS 实现弹性文字效果
前端·css
牛奶4 小时前
Vue 基础理论 & API 使用
前端·vue.js·面试
牛奶4 小时前
Vue 底层原理 & 新特性
前端·vue.js·面试
anOnion4 小时前
构建无障碍组件之Radio group pattern
前端·html·交互设计
pe7er4 小时前
状态提升:前端开发中的状态管理的设计思想
前端·vue.js·react.js
SoaringHeart5 小时前
Flutter调试组件:打印任意组件尺寸位置信息 NRenderBox
前端·flutter
晚风予星6 小时前
Ant Design Token Lens 迎来了全面升级!支持在 .tsx 或 .ts 文件中直接使用 Design Token
前端·react.js·visual studio code
sunny_6 小时前
⚡️ vite-plugin-oxc:从 Babel 到 Oxc,我为 Vite 写了一个高性能编译插件
前端·webpack·架构
GIS之路6 小时前
ArcPy 开发环境搭建
前端
林小帅8 小时前
【笔记】OpenClaw 架构浅析
前端·agent