05-初始化登录页面和加入校验规则

App 组件

html 复制代码
<template>
  <div class=''>
    <router-view></router-view>
  </div>
</template>

<script lang='ts' setup>
import { } from 'vue'

</script>

<style lang='less'>
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
}

#app {
    height: 100%;
    overflow: hidden;
}
</style>

login 组件

html 复制代码
<template>
    <div class="login-rule-form">
        <div class="content">
            <div class="title">商品管理系统</div>
            <el-form ref="ruleFormRef" :model="ruleForm" status-icon :rules="rules" label-width="60px">
                <el-form-item prop="username" label="账号">
                    <el-input v-model="ruleForm.username" type="text" placeholder="请输入账号"/>
                </el-form-item>
                <el-form-item prop="pwd" label="密码">
                    <el-input v-model="ruleForm.pwd" type="password" placeholder="请输入密码"/>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="loginFn()">登录</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script lang='ts' setup>
import { reactive } from 'vue'

let ruleForm = reactive({
    username: "",
    pwd: ""
})
// 自定义密码校验规则
const validatePwd = (rule: unknown, value: string | undefined, callback: (msg?: string) => void) => {
    if(!value) {
        callback('密码不能为空')
    } else {
        callback()
    }
}
// 校验规则
let rules = reactive({
    username: [
        {
            required: true,
            message: '用户名不能为空',
            trigger: 'blur'
        }
    ],
    pwd: [
        {
            required: true,
            validator: validatePwd,
            trigger: 'blur'
        }
    ]
})

// 登录
const loginFn = () => {

}

</script>

<style lang='less' scoped>
.login-rule-form {
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #f5f5f5;
    overflow: hidden;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    .content {
        width: 420px;
        padding: 40px;
        background-color: #fff;
        border-radius: 8px;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
        box-sizing: border-box;
        .title {
            font-size: 28px;
            font-weight: bold;
            text-align: center;
            margin-bottom: 30px;
        }
    }

    :deep(.el-form) {
        .el-form-item {
            margin-bottom: 20px;
            &:last-child {
                margin-bottom: 0;
            }
        }
        .el-button {
            width: 100%;
        }
    }
}
</style>
相关推荐
Jeking2174 天前
进阶流程图绘制工具 Unione Flow Editor-- 巧用Event事件机制,破解复杂业务交互难题
流程图·vue3·workflow·unione flow·flow editor·unione cloud
一只小阿乐5 天前
前端vue3 web端中实现拖拽功能实现列表排序
前端·vue.js·elementui·vue3·前端拖拽
AAA阿giao5 天前
从“操纵绳子“到“指挥木偶“:Vue3 Composition API 如何彻底改变前端开发范式
开发语言·前端·javascript·vue.js·前端框架·vue3·compositionapi
૮・ﻌ・5 天前
Vue3:组合式API、Vue3.3新特性、Pinia
前端·javascript·vue3
凯小默8 天前
37-实现地图配置项(完结)
echarts·vue3
凯小默9 天前
36-引入地图
echarts·vue3
凯小默9 天前
【TypeScript+Vue3+Vite+Vue-router+Vuex+Mock 进行 WEB 前端项目实战】学习笔记共 89 篇(完结)
typescript·echarts·mock·vue3·vite·vuex·vue-router
凯小默10 天前
34-监听数据渲染饼图以及饼图配置
vue3
凯小默11 天前
30-更新用户信息并且刷新表格
vue3
凯小默11 天前
27-编辑用户信息弹框组件化(显示隐藏功能)
vue3