vue登陆页面

一. 内容简介

vue登陆页面实现。

二. 软件环境

2.1 Visual Studio Code 1.75.0

2.2 chrome浏览器

2.3 node v18.14.0

三.主要流程

3.1 搭建html结构

3.2 添加css样式

3.3 js代码

3.4 页面展示

3.5 vue组件完整代码

四.具体步骤

4.1 搭建html结构

<div class="login">

    <!-- 用于显示名字 -->
    <div class="header">
        <p class="title">竞赛助手平台</p>
    </div>

    <!-- 内容 -->
    <div class="content">
        <!-- 放图片 -->
        <div class="content-left">
            <img src="@/static/img/loginBg1.jpg" class="img-bg">
        </div>
        <!-- 放表单 -->
        <div class="content-right">
            <!-- 参赛者登录 -->
            <div class="content-right-title">参赛者登录</div>
            <form action="">
                <div class="user-name" style="margin-top: 60px;">
                    <label for="user"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></label>
                    <input type="text" class="ant-row ant-form-item" v-model="username" placeholder="邮箱/手机/用户名"
                        @keyup="checkInfo">
                </div>
                <div class="user-pass" style="margin-top: 60px;">
                    <label for="password"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span></label>
                    <input type="password" class="ant-row ant-form-item" v-model="password" placeholder="请输入密码"
                        @keyup="checkInfo">
                </div>
                <div class="user-pass user-yzm" style="margin-top: 60px;">
                    <div>
                        <label for="yzm"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span></label>
                        <input type="yzm" class="ant-row ant-form-item" placeholder="请输入验证码">
                    </div>
                    <div><img src="@/static/img/yzm.jpg" class="img-yzm" alt=""></div>
                </div>
            </form>
            <!-- 注册,忘记密码 -->
            <div class="tip">{{tips}}</div>
            <div class="register">
                <a class="register-a" href="">忘记密码</a>
                <a class="register-a" href="">注册账号</a>
            </div>
            <!-- 登录按钮 -->
            <div class="register-button">
                <input type="button" @click="doSubmit" value="登 录" class="btn btn-primary register-button-btn">
            </div>
        </div>
    </div>
    
    <!-- 底部信息 -->
    <div class="footer">
    
    </div>
</div>

4.2 添加css样式

/* 初始配置 */
* {
  margin: 0;
  padding: 0;
}
ul,ol {
  list-style: none;
}
img {
  display: block;
}
a {
  text-decoration: none;
}
h1,h2,h3 {
  font-size: 16px;
}
body {
  font-family: Arial, Helvetica, sans-serif;
}

/* 浮动 */
.l {
  float: left;
}
.r {
  float: right;
}
.clear::after {
  content:"";
  display: block;
  clear: both;
}

/* 版心 */
.container {
  width: 1080px;
  margin: 0 auto;
  position: relative;
}
/* 通栏 */
.container-fluid {
  width: 100%;
}

/* 页面配置 */
.login {
    height: 1009px;
    background: #f0f2f5;
}
.header {
    width: 100%;
    height: 160px;
    display: flex;
    justify-content:center;
}
.title {
    font-size: 33px;
    color: rgba(0, 0, 0, .85);
    font-family: Chinese Quote, -apple-system, BlinkMacSystemFont, Segoe UI, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Helvetica Neue, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
    font-weight: 600;
    position: relative;
    top: 75px;
}

.content {
    margin: 0 auto;
    width: 1000px;
    height: 620px;
    background: #ffffff;
    border-radius: 40px;
    display: flex;
    justify-content: space-around;
    align-items: center; 
}
.img-bg {
    height: 480;
    width: 533px;
}
.content-left {
    height: 100%;
    display: flex;
    align-items:center;
}
.content-right {
    width: 400px;
    height: 100%;
    margin-top:50px;
    padding: 30px;
}
.content-right-title {
    text-align: center;
    font-size: 20px;
    font-weight: bold;
    padding-bottom: 10px;
}
.user-yzm {
    display: flex;

}
.img-yzm {
    height: 40px;
    margin-right: 0px;
    margin-left: 10px;
}

/* 登录 */
.register {
    margin-top: 0px;
    line-height: 40px;
    display: flex;
    flex-direction: row-reverse;
}
.register-a {
    margin-left: 10px;
}
.register-button {
    line-height: 1.499;
    font-weight: 400;
    width: 100%;
    margin-top: 20px;
}
.register-button-btn {
    width: 100%;
    border-radius: 7px;
}
.tip {
    margin: 0;
    padding: 20px;
    height: 30px;
    width: 100%;
    color: red;
}

4.3 js代码

export default {
    data() {
        return {
            username: "",
            password: "",
            tips: "",
            colorStyle: "color:red",
            isRight: false,
            returnUrl: null,
            pid: 0,
            sid: 0,
            num: 1
        }
    },
    methods: {
        doSubmit: function () {
            if (this.isRight) {
                var url = "http://localhost:8080/user/login";
                axios.get(url, {
                    params: {
                        username: this.username,
                        password: this.password
                    }
                }).then((res) => {
                    //res.data 才表示接口返回的数据
                    var vo = res.data;
                    console.log(vo);

                    if (vo.code == 10000) {
						this.tips = "登录成功!";
                           }
                    } else {
                        this.tips = "登录失败,账号或密码错误!";
                    }
                });
            } else {
                this.tips = "请正确输入帐号和密码!";
            }
        },
        checkInfo: function () {
            if (this.username == "") {
                this.tips = "请输入帐号!";
                this.isRight = false;
            } else if (this.username.length < 8 || this.username.length > 20) {
                this.tips = "账号长度必须为8-20个字符!";
                this.isRight = false;
            } else {
                //账号合法,校验密码
                if (this.password == "") {
                    this.tips = "请输入密码!";
                    this.isRight = false;
                } else if (this.password.length < 6 || this.password.length > 16) {
                    this.tips = "密码长度必须为6-16个字符!";
                    this.isRight = false;
                } else {
                    this.tips = "";
                    this.isRight = true;
                }
            }
        }
    }
}

4.4 页面展示

在这里插入图片描述
在这里插入图片描述

4.5 vue组件完整代码

<template>
    <div class="login">
        <!-- 用于显示名字 -->
        <div class="header">
            <p class="title">竞赛助手平台</p>
        </div>
        
        <!-- 内容 -->
        <div class="content">
            <!-- 放图片 -->
            <div class="content-left">
                <img src="@/static/img/loginBg1.jpg" class="img-bg">
            </div>
            <!-- 放表单 -->
            <div class="content-right">
                <!-- 参赛者登录 -->
                <div class="content-right-title">参赛者登录</div>
                <form action="">
					<div class="user-name"  style="margin-top: 60px;">
						<label for="user"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></label>
						<input type="text" class="ant-row ant-form-item" v-model="username" placeholder="邮箱/手机/用户名" @keyup="checkInfo">
					</div>
					<div class="user-pass"  style="margin-top: 60px;">
						<label for="password"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span></label>
						<input type="password" class="ant-row ant-form-item" v-model="password" placeholder="请输入密码" @keyup="checkInfo">
					</div>
					<div class="user-pass user-yzm"  style="margin-top: 60px;">
                        <div>
                            <label for="yzm"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span></label>
                            <input type="yzm" class="ant-row ant-form-item" placeholder="请输入验证码" >
                        </div>
                        <div><img src="@/static/img/yzm.jpg" class="img-yzm" alt=""></div>
					</div>
                </form>
                <!-- 注册,忘记密码 -->
                <div class="tip">{{tips}}</div>
                <div class="register">
                    <a class="register-a" href="">忘记密码</a>
                    <a class="register-a" href="">注册账号</a>
                </div>
                <!-- 登录按钮 -->
                <div class="register-button">
                    <input  type="button" @click="doSubmit" value="登 录" class="btn btn-primary register-button-btn">
                </div>
            </div>            
        </div>



        <!-- 底部信息 -->
        <div class="footer">

        </div>

    </div>
</template>
<script>
import "../static/js/jquery-1.9.min.js"
import "../static/js/cookie_utils.js"
import "../static/js/vue.js"
import "../static/js/utils.js"
import axios from "../static/js/axios.min.js"
import "../static/js/base.js"
    export default {
        data(){
            return {
                username:"",
				password:"",
				tips:"",
				colorStyle:"color:red",
				isRight:false,
				returnUrl:null,
				pid:0,
				sid:0,
				num:1
            }
        }
		},
        methods: {
            doSubmit: function() {
                if (this.isRight) {
                    var url = "http://localhost:8080/user/login";
                    axios.get(url, {
                        params: {
                            username: this.username,
                            password: this.password
                        }
                    }).then((res) => {
                        //res.data 才表示接口返回的数据
                        var vo = res.data;
                        console.log(vo);

                        if (vo.code == 10000) {
         
                                }
                        } else {
                            this.tips = "登录失败,账号或密码错误!";
                        }
                    });

                } else {
                    this.tips = "请正确输入帐号和密码!";
                }
            },
            checkInfo: function() {
                if (this.username == "") {
                    this.tips = "请输入帐号!";
                    this.isRight = false;
                } else if (this.username.length < 8 || this.username.length > 20) {
                    this.tips = "账号长度必须为8-20个字符!";
                    this.isRight = false;
                } else {
                    //账号合法,校验密码
                    if (this.password == "") {
                        this.tips = "请输入密码!";
                        this.isRight = false;
                    } else if (this.password.length < 6 || this.password.length > 16) {
                        this.tips = "密码长度必须为6-16个字符!";
                        this.isRight = false;
                    } else {
                        this.tips = "";
                        this.isRight = true;
                    }
                }
            }
        }
        
    } 
</script>
<style src="@/static/css/dlstyle.css"  scoped></style>
<style src="@/static/css/bootstrap.min.css"  scoped></style>
<style scoped>
/* 初始配置 */
* {
  margin: 0;
  padding: 0;
}
ul,ol {
  list-style: none;
}
img {
  display: block;
}
a {
  text-decoration: none;
}
h1,h2,h3 {
  font-size: 16px;
}
body {
  font-family: Arial, Helvetica, sans-serif;
}

/* 浮动 */
.l {
  float: left;
}
.r {
  float: right;
}
.clear::after {
  content:"";
  display: block;
  clear: both;
}

/* 版心 */
.container {
  width: 1080px;
  margin: 0 auto;
  position: relative;
}
/* 通栏 */
.container-fluid {
  width: 100%;
}

/* 页面配置 */
.login {
    height: 1009px;
    background: #f0f2f5;
}

.header {
    width: 100%;
    height: 160px;
    display: flex;
    justify-content:center;
}
.title {
    font-size: 33px;
    color: rgba(0, 0, 0, .85);
    font-family: Chinese Quote, -apple-system, BlinkMacSystemFont, Segoe UI, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Helvetica Neue, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
    font-weight: 600;
    position: relative;
    top: 75px;
}

/* 内容配置 */
.content {
    margin: 0 auto;
    width: 1000px;
    height: 620px;
    background: #ffffff;
    border-radius: 40px;
    display: flex;
    justify-content: space-around;
    align-items: center; 
}
.img-bg {
    height: 480;
    width: 533px;
}
.content-left {
    height: 100%;
    display: flex;
    align-items:center;
}
.content-right {
    width: 400px;
    height: 100%;
    margin-top:50px;
    padding: 30px;
}
.content-right-title {
    text-align: center;
    font-size: 20px;
    font-weight: bold;
    padding-bottom: 10px;
}
.user-yzm {
    display: flex;

}
.img-yzm {
    height: 40px;
    margin-right: 0px;
    margin-left: 10px;
}

/* 登录 */
.register {
    margin-top: 0px;
    line-height: 40px;
    display: flex;
    flex-direction: row-reverse;
}
.register-a {
    margin-left: 10px;
}
.register-button {
    line-height: 1.499;
    font-weight: 400;
    width: 100%;
    margin-top: 20px;
}
.register-button-btn {
    width: 100%;
    border-radius: 7px;
}
.tip {
    margin: 0;
    padding: 20px;
    height: 30px;
    width: 100%;
    color: red;
}
</style>

五. 问题

导入css,js有点麻烦,

<style src="@/static/css/dlstyle.css"  scoped></style>
<style src="@/static/css/bootstrap.min.css"  scoped></style>
<style scoped>

<script>
import "../static/js/jquery-1.9.min.js"
import "../static/js/cookie_utils.js"
import "../static/js/vue.js"
import "../static/js/utils.js"
import axios from "../static/js/axios.min.js"
import "../static/js/base.js"
  • 10
    点赞
  • 94
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,以下是一个简单的Vue登录界面的代码示例: ``` <template> <div class="login-container"> <h2>用户登录</h2> <form> <div class="form-group"> <label for="username">用户名:</label> <input type="text" id="username" v-model="username" placeholder="请输入用户名"> </div> <div class="form-group"> <label for="password">密码:</label> <input type="password" id="password" v-model="password" placeholder="请输入密码"> </div> <div class="form-group"> <button type="button" @click="login">登录</button> </div> </form> </div> </template> <script> export default { data() { return { username: '', password: '' } }, methods: { login() { // 在这里编写登录逻辑 console.log(`用户名:${this.username},密码:${this.password}`); } } } </script> <style scoped> .login-container { display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100vh; } form { display: flex; flex-direction: column; align-items: center; margin-top: 20px; padding: 20px; background-color: #f5f5f5; border-radius: 5px; } .form-group { display: flex; flex-direction: row; align-items: center; margin: 10px 0; } label { font-size: 16px; margin-right: 10px; } input { padding: 5px; border-radius: 5px; border: none; outline: none; box-shadow: 0 0 5px rgba(0, 0, 0, 0.3); font-size: 16px; } button { padding: 10px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; font-size: 16px; cursor: pointer; } </style> ``` 这个代码示例中,我们使用了Vue的单文件组件形式,包含了模板、脚本和样式。其中,模板中定义了登录界面的HTML结构,脚本中定义了数据和方法,样式中定义了界面的样式。 在这个示例中,我们使用了Vue的数据绑定功能,将表单中的用户名和密码与组件中的数据进行绑定。当用户输入用户名和密码后,我们在登录按钮的点击事件中,可以获取到输入框中的数据,然后进行登录逻辑的处理。 当然,这个示例只是一个简单的登录界面,实际开发中,你需要根据具体需求进行功能的扩展和优化。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值