uniapp的form表单自定义验证规则

template部分:

			
				
			
			
				
			
			
				
			
			
		
 data部分:
user: {
					oldPassword: undefined,
					newPassword: undefined,
					confirmPassword: undefined
				},
				rules: {
					oldPassword: {
						rules: [{
							required: true,
							errorMessage: '旧密码不能为空'
						}]
					},
					newPassword: {
						rules: [{
								required: true,
								errorMessage: '新密码不能为空',
							},
							{
								minLength: 6,
								maxLength: 20,
								errorMessage: '长度在 6 到 20 个字符'
							}
						]
					},
					confirmPassword: {
						rules: [{
							required: true,
							errorMessage: '确认密码不能为空'
						}, {
							validateFunction: (rule, value, data) => data.newPassword === value,
							errorMessage: '两次输入的密码不一致'
						}]
					}
				}

 

methods部分:
submit() {
				this.$refs.form.validate().then(res => {
				updateUserPwd(this.user.oldPassword,this.user.newPassword).then(response =>           {
						this.$modal.msgSuccess("修改成功")
					})
				})
			}

你可能感兴趣的:(uni-app,java,前端)