<template>
<div class="login">
<div class="login_box">
<!-- 表单 -->
<el-form :model="loginForm" :rules="loginFormRules" ref="loginFormRef">
<!-- 2行表单输入框 -->
<el-form-item prop="username">
<el-input v-model="loginForm.username" prefix-icon="el-icon-user-solid"></el-input>
</el-form-item>
<el-form-item prop="password">
<el-input v-model="loginForm.password" type="password" prefix-icon="el-icon-lock"></el-input>
</el-form-item>
<!-- 按钮 -->
<el-form-item class="btns">
<el-button type="primary">登陆</el-button>
<el-button type="info" @click="resetLoginForm">重置</el-button>
</el-form-item>
</el-form>
</div>
</div>
</template>
<script>
export default {
data () {
return {
loginForm: {
username: '',
password: ''
},
loginFormRules: {
username: [
{ required: true, message: '请输入登陆账号', trigger: 'blur' },
{ min: 3, max: 10, message: '长度在3-10个字符',trigger: 'blur' }
],
password: [
{ required: true, message: '请输入登陆密码', trigger: 'blur' },
{ min: 6, max: 15, message: '长度在6-15个字符',trigger: 'blur' }
]
}
}
},
methods: {
resetLoginForm () {
this.$refs.loginFormRef.resetFields()
}
}
}
</script>
基于element插件的表单验证及重置
最新推荐文章于 2024-06-02 00:14:46 发布