mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-15 18:01:24 +08:00
57 lines
1.2 KiB
Vue
57 lines
1.2 KiB
Vue
|
<template>
|
||
|
<el-form
|
||
|
ref="numberValidateForm"
|
||
|
:model="numberValidateForm"
|
||
|
label-width="100px"
|
||
|
class="demo-ruleForm"
|
||
|
>
|
||
|
<el-form-item
|
||
|
label="age"
|
||
|
prop="age"
|
||
|
:rules="[
|
||
|
{ required: true, message: 'age is required' },
|
||
|
{ type: 'number', message: 'age must be a number' },
|
||
|
]"
|
||
|
>
|
||
|
<el-input
|
||
|
v-model.number="numberValidateForm.age"
|
||
|
type="age"
|
||
|
autocomplete="off"
|
||
|
></el-input>
|
||
|
</el-form-item>
|
||
|
<el-form-item>
|
||
|
<el-button type="primary" @click="submitForm('numberValidateForm')"
|
||
|
>Submit</el-button
|
||
|
>
|
||
|
<el-button @click="resetForm('numberValidateForm')">Reset</el-button>
|
||
|
</el-form-item>
|
||
|
</el-form>
|
||
|
</template>
|
||
|
|
||
|
<script lang="ts">
|
||
|
export default {
|
||
|
data() {
|
||
|
return {
|
||
|
numberValidateForm: {
|
||
|
age: '',
|
||
|
},
|
||
|
}
|
||
|
},
|
||
|
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()
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
</script>
|