<template>
<div>
<el-button type="text" @click="dialogVisible = true">点击打开 Dialog</el-button>
<el-dialog title="提示" :visible.sync="dialogVisible" width="60%">
<el-form :inline="true" :model="form" class="demo-form-inline" :rules="rules" ref="ruleForm">
<el-form-item label="审批人" required>
<el-form-item prop='rulesdi'>
<el-input v-model="form.di" @input="checkNumber('di')" />
</el-form-item>
<el-form-item prop='rulesgao'>
<el-input v-model="form.gao" @input="checkNumber('gao')" />
</el-form-item>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="add">确 定</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
export default {
data () {
const validatedi = (rule, value, callback) => {
const di = Number(value)
const gao = Number(this.form.gao)
if (di === '' || di == 0) {
callback(new Error('请输入'));
}
if (isNaN(di)) {
callback(new Error('请输入数字'));
}
if (di > gao) {
callback(new Error('不能大于高'));
}
callback()
};
const validategao = (rule, value, callback) => {
const gao = Number(value)
const di = Number(this.form.di)
if (gao === '' || gao == 0) {
callback(new Error('请输入'));
}
if (isNaN(gao)) {
callback(new Error('请输入数字'));
}
if (gao < di) {
callback(new Error('不能小于低'));
}
callback()
};
return {
dialogVisible: false,
form: {
di: '',
gao: ''
},
rules: {
rulesdi: [
{ required: true, validator: validatedi, trigger: 'blur' }
],
rulesgao: [
{ required: true, validator: validategao, trigger: 'blur' }
],
}
}
},
methods: {
add () {
console.log(this.form);
},
checkNumber (type) {
if (type === 'di') {
this.$refs.ruleForm.validateField('rulesgao');
} else {
this.$refs.ruleForm.validateField('rulesdi');
}
},
}
}
</script>
<style>
</style>
多个输入框校验,最大值和最小值相互校验
于 2022-06-12 23:22:52 首次发布