登录数据数据验证,学习element plus组件种页面数据验证
UserLogin.vue页面
<template> <div class="login"> <div class="body"> <div class="container"> <h2>用户登陆</h2> <el-form :model="ruleForm" ref="loginForm" class="login-form" :rules="rules"> <el-form-item label="账号" prop="email"> <el-input v-model="ruleForm.email" /> </el-form-item> <el-form-item label="密码" prop="password"> <el-input type="password" v-model="ruleForm.password" /> </el-form-item> <el-button style="width: 100%;" type="primary" @click="submitForm(loginForm)">登陆</el-button> </el-form> </div> </div> </div> </template> <script setup> import { reactive, toRefs, ref } from 'vue'; const loginForm = ref() const state = reactive({ ruleForm: { email: "[email protected]", password: "ant123" } }) const rules = reactive({ email: [ { required: true, message: '请输入账号', trigger: 'blur' } ], password: [ { required: true, message: '请输入密码', trigger: 'blur' } ] }) const submitForm = async (formEl) => { if (!formEl) return await formEl.validate(() => { //验证通过进行登陆 console.log('submit!') }) } const { ruleForm } = toRefs(state) </script> <style scoped> .login { background: url("../../assets/bg.jpg"); height: 100%; width: 100%; position: fixed; background-size: cover; } .body { display: flex; justify-content: center; align-items: center; margin-top: 20%; } .container { width: 420px; height: 250px; background-color: white; display: flex; justify-content: center; align-items: center; flex-direction: column; border-radius: 10px; border-radius: 0px 21px 41px 0px rgba(0, 0, 0, 0.2); font-size: 12px; } </style>
标签:flex,VUE,const,center,笔记,学习,reactive,background,password From: https://www.cnblogs.com/Lvkang/p/18219692