mirror of
https://github.com/element-plus/element-plus.git
synced 2025-08-14 18:11:48 +08:00
fix(style): adjust component size & demo (#4801)
* fix(style): adjust button size & demo spacing * fix(style): adjust input padding & with prefix/suffix * fix(style): adjust button padding horizontal * fix(style): adjust form margin & font-size * refactor(docs): use setup simplify form examples
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<el-form
|
||||
ref="ruleForm"
|
||||
ref="ruleFormRef"
|
||||
:model="ruleForm"
|
||||
status-icon
|
||||
:rules="rules"
|
||||
@ -25,79 +25,69 @@
|
||||
<el-input v-model.number="ruleForm.age"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="submitForm('ruleForm')"
|
||||
<el-button type="primary" @click="submitForm(ruleFormRef)"
|
||||
>Submit</el-button
|
||||
>
|
||||
<el-button @click="resetForm('ruleForm')">Reset</el-button>
|
||||
<el-button @click="resetForm(ruleFormRef)">Reset</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
data() {
|
||||
const checkAge = (rule, value, callback) => {
|
||||
if (!value) {
|
||||
return callback(new Error('Please input the age'))
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (!Number.isInteger(value)) {
|
||||
callback(new Error('Please input digits'))
|
||||
} else {
|
||||
if (value < 18) {
|
||||
callback(new Error('Age must be greater than 18'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
const validatePass = (rule, value, callback) => {
|
||||
if (value === '') {
|
||||
callback(new Error('Please input the password'))
|
||||
} else {
|
||||
if (this.ruleForm.checkPass !== '') {
|
||||
this.$refs.ruleForm.validateField('checkPass')
|
||||
}
|
||||
callback()
|
||||
}
|
||||
}
|
||||
const validatePass2 = (rule, value, callback) => {
|
||||
if (value === '') {
|
||||
callback(new Error('Please input the password again'))
|
||||
} else if (value !== this.ruleForm.pass) {
|
||||
callback(new Error("Two inputs don't match!"))
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive } from 'vue'
|
||||
// More info see https://github.com/element-plus/element-plus/blob/dev/docs/examples/form/utils.ts
|
||||
import { resetForm, submitForm } from './utils'
|
||||
import type { ElForm } from 'element-plus'
|
||||
|
||||
const ruleFormRef = ref<InstanceType<typeof ElForm>>()
|
||||
|
||||
const checkAge = (rule: any, value: any, callback: any) => {
|
||||
if (!value) {
|
||||
return callback(new Error('Please input the age'))
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (!Number.isInteger(value)) {
|
||||
callback(new Error('Please input digits'))
|
||||
} else {
|
||||
if (value < 18) {
|
||||
callback(new Error('Age must be greater than 18'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
return {
|
||||
ruleForm: {
|
||||
pass: '',
|
||||
checkPass: '',
|
||||
age: '',
|
||||
},
|
||||
rules: {
|
||||
pass: [{ validator: validatePass, trigger: 'blur' }],
|
||||
checkPass: [{ validator: validatePass2, trigger: 'blur' }],
|
||||
age: [{ validator: checkAge, trigger: 'blur' }],
|
||||
},
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
submitForm(formName) {
|
||||
this.$refs[formName].validate((valid) => {
|
||||
if (valid) {
|
||||
alert('submit!')
|
||||
} else {
|
||||
console.log('error submit!!')
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
resetForm(formName) {
|
||||
this.$refs[formName].resetFields()
|
||||
},
|
||||
},
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
const validatePass = (rule: any, value: any, callback: any) => {
|
||||
if (value === '') {
|
||||
callback(new Error('Please input the password'))
|
||||
} else {
|
||||
if (ruleForm.checkPass !== '') {
|
||||
if (!ruleFormRef.value) return
|
||||
ruleFormRef.value.validateField('checkPass', () => null)
|
||||
}
|
||||
callback()
|
||||
}
|
||||
}
|
||||
const validatePass2 = (rule: any, value: any, callback: any) => {
|
||||
if (value === '') {
|
||||
callback(new Error('Please input the password again'))
|
||||
} else if (value !== ruleForm.pass) {
|
||||
callback(new Error("Two inputs don't match!"))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
const ruleForm = reactive({
|
||||
pass: '',
|
||||
checkPass: '',
|
||||
age: '',
|
||||
})
|
||||
|
||||
const rules = reactive({
|
||||
pass: [{ validator: validatePass, trigger: 'blur' }],
|
||||
checkPass: [{ validator: validatePass2, trigger: 'blur' }],
|
||||
age: [{ validator: checkAge, trigger: 'blur' }],
|
||||
})
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user