// 自定义确认密码匹配验证规则
const matchPassword = (rules:any, value:any, callback:any) => {
if (value != addData.payPwd) {
callback(new Error('两次密码输入不一致!'))
} else {
callback()
}
}
const rules = reactive({
payPwd: [
{ required: true, message: "请输入支付密码", trigger: "blur" },
{
pattern: /^\d+$/,
message: "只能输入6位数字",
trigger: "blur",
},
],
repeatedPwd: [
{ required: true, message: "请输入支付密码", trigger: "blur" },
{
pattern: /^\d+$/,
message: "只能输入6位数字",
trigger: "blur",
},
{validator: matchPassword, trigger: 'blur'}
],
});
<el-dialog
v-model="AddDialog"
title="新增会员"
width="700px"
@close="closeDialog"
>
<el-form
ref="categoryFormRef"
:model="addData"
:rules="rules"
label-width="120px"
>
<el-form-item label="支付密码" prop="payPwd">
<el-input
v-model="addData.payPwd"
placeholder="请输入支付密码"
show-password
maxLength="6"
/>
</el-form-item>
<el-form-item label="确认支付密码" prop="repeatedPwd">
<el-input
v-model="addData.repeatedPwd"
placeholder="请输入支付密码"
show-password
maxLength="6"
/>
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="handleAdd">确 定</el-button>
<el-button @click="closeDialog">取 消</el-button>
</div>
</template>
</el-dialog>