若依前端分离版-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,
相关推荐
清幽竹客23 分钟前
vue-37(模拟依赖项进行隔离测试)
前端·vue.js
vvilkim23 分钟前
Nuxt.js 页面与布局系统深度解析:构建高效 Vue 应用的关键
前端·javascript·vue.js
滿27 分钟前
Vue3 父子组件表单滚动到校验错误的位置实现方法
前端·javascript·vue.js
夏梦春蝉1 小时前
ES6从入门到精通:模块化
前端·ecmascript·es6
拓端研究室2 小时前
视频讲解:门槛效应模型Threshold Effect分析数字金融指数与消费结构数据
前端·算法
工一木子3 小时前
URL时间戳参数深度解析:缓存破坏与前端优化的前世今生
前端·缓存
半点寒12W5 小时前
微信小程序实现路由拦截的方法
前端
某公司摸鱼前端6 小时前
uniapp socket 封装 (可拿去直接用)
前端·javascript·websocket·uni-app
要加油哦~6 小时前
vue | 插件 | 移动文件的插件 —— move-file-cli 插件 的安装与使用
前端·javascript·vue.js
小林学习编程6 小时前
Springboot + vue + uni-app小程序web端全套家具商场
前端·vue.js·spring boot