• 【前端】Vue+Element UI案例:通用后台管理系统-登陆页面Login



    参考视频: VUE项目,VUE项目实战,vue后台管理系统,前端面试,前端面试项目

    案例链接
    【前端】Vue+Element UI案例:通用后台管理系统-导航栏(视频p1-16)https://blog.csdn.net/karshey/article/details/127640658
    【前端】Vue+Element UI案例:通用后台管理系统-Header+导航栏折叠(p17-19)https://blog.csdn.net/karshey/article/details/127652862
    【前端】Vue+Element UI案例:通用后台管理系统-Home组件:卡片、表格(p20-22)https://blog.csdn.net/karshey/article/details/127674643
    【前端】Vue+Element UI案例:通用后台管理系统-Echarts图表准备:axios封装、mock数据模拟实战(p23-25)https://blog.csdn.net/karshey/article/details/127735159
    【前端】Vue+Element UI案例:通用后台管理系统-Echarts图表:折线图、柱状图、饼状图(p27-30)https://blog.csdn.net/karshey/article/details/127737979
    【前端】Vue+Element UI案例:通用后台管理系统-面包屑、tag栏(p31-35)https://blog.csdn.net/karshey/article/details/127756733
    【前端】Vue+Element UI案例:通用后台管理系统-用户管理:Form表单填写、Dialog对话框弹出(p36-38)https://blog.csdn.net/karshey/article/details/127787418
    【前端】Vue+Element UI案例:通用后台管理系统-用户管理:Table表格增删查改、Pagination分页、搜索框(p39-42)https://blog.csdn.net/karshey/article/details/127777962
    【前端】Vue+Element UI案例:通用后台管理系统-登陆页面Login(p44)https://blog.csdn.net/karshey/article/details/127795302
    【前端】Vue+Element UI案例:通用后台管理系统-登陆页面功能:登录权限跳转、路由守卫、退出(p45-46)https://blog.csdn.net/karshey/article/details/127849502
    【前端】Vue+Element UI案例:通用后台管理系统-登陆不同用户显示不同菜单、动态添加路由(p47-48)https://blog.csdn.net/karshey/article/details/127865621
    【前端】Vue+Element UI案例:通用后台管理系统-项目总结https://blog.csdn.net/karshey/article/details/127867638

    本篇很短,因为只有一个页面。没有功能。

    目标

    在这里插入图片描述

    • 登陆页面,路由为/login
    • 有表单验证

    代码

    0.路由

    在router的index.js文件中的routes中添加对象:

    {
        path:'/login',
        component:Login
    }
    
    • 1
    • 2
    • 3
    • 4

    1.结构

    显然是表单,我们对表单已经很熟悉了。

    在这里插入图片描述

    <template>
        <el-form :model="login" status-icon :rules="rules" ref="login" label-width="100px">
            
            <h3 class="login_title">用户登录h3>
            
            <el-form-item label="用户名" prop="username">
                <el-input type="password" v-model="login.username" autocomplete="off">el-input>
            el-form-item>
    
            <el-form-item label="密码" prop="password">
                <el-input type="password" v-model="login.password" autocomplete="off">el-input>
            el-form-item>
    
            <el-form-item>
                <el-button type="primary">提交el-button>
            el-form-item>
        el-form>
    template>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    2.校验规则

    // 校验规则
    rules: {
        username:[{required:'true',message:'请输入用户名',trigger:'blur'}],
        password:[{required:'true',message:'请输入用户名',trigger:'blur'}]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    效果:

    在这里插入图片描述

    3.样式

    css:

    .login_container {
        width: 350px;
        border: 1px solid #eaeaea;
    
        // 居中
        margin: 180px auto;
    
        padding: 35px 35px 15px 35px;
    
        // 让padding在width里面
        box-sizing: border-box;
    
        border-radius: 15px;
        background-color: #fff;
        box-shadow: 0 0 25px #cac6c6;
    
        .login_title {
            color: #505458;
            // 左右居中
            text-align: center;
            margin-bottom: 40px;
        }
    
        .el-input {
            width: 198px;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    在html中的样式:

    表单域标签的宽度。

    <el-form 
    class="login_container" 
    :model="login" 
    status-icon :rules="rules" 
    ref="login" 
    label-width="70px">
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    让提交button在中间:

    <el-form-item>
        <el-button type="primary" 
        style="margin-left:30px;margin-top:10px">
        提交
        el-button>
    el-form-item>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    总代码

    Login.vue

    <template>
        <el-form class="login_container" :model="login" status-icon :rules="rules" ref="login" label-width="70px">
            
            <h3 class="login_title">用户登录h3>
            
            <el-form-item label="用户名" prop="username">
                <el-input v-model="login.username" autocomplete="off">el-input>
            el-form-item>
    
            <el-form-item label="密码" prop="password">
                <el-input type="password" v-model="login.password" autocomplete="off">el-input>
            el-form-item>
    
            <el-form-item>
                <el-button type="primary" style="margin-left:30px;margin-top:10px">提交el-button>
            el-form-item>
        el-form>
    template>
    
    <script>
    export default {
        data() {
            return {
                // 登陆数据
                login: {
                    username: '',
                    password: ''
                },
                // 校验规则
                rules: {
                    username: [{ required: 'true', message: '请输入用户名', trigger: 'blur' }],
                    password: [{ required: 'true', message: '请输入用户名', trigger: 'blur' }]
                }
            }
        },
    }
    script>
    
    <style lang="less" scoped>
    .login_container {
        width: 350px;
        border: 1px solid #eaeaea;
    
        // 居中
        margin: 180px auto;
    
        padding: 35px 35px 15px 35px;
    
        // 让padding在width里面
        box-sizing: border-box;
    
        border-radius: 15px;
        background-color: #fff;
        box-shadow: 0 0 25px #cac6c6;
    
        .login_title {
            color: #505458;
            // 左右居中
            text-align: center;
            margin-bottom: 40px;
        }
    
        .el-input {
            width: 198px;
        }
    }
    style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67

    效果

    在这里插入图片描述
    表单验证失败:
    在这里插入图片描述
    表单验证成功:
    在这里插入图片描述

  • 相关阅读:
    聊天机器人
    Labview+STM32无线温湿度采集
    stable-diffusion-webui中stability的sdv1.5和sdxl模型结构config对比
    DDoS攻击和CC攻击
    Redis目录
    用1100天做一款通用的管理后台框架
    Spring面试题
    uboot移植之环境变量bootargs
    Python_玩转多线程_一蓑烟雨任平生
    JavaScript 伪数组和数组
  • 原文地址:https://blog.csdn.net/karshey/article/details/127795302