VSCode创建VUE项目(二)前端登录页面

一.创建登录页面

代码:

javascript 复制代码
<template>
    <div class="login-container dis-h">
       <div class="login-form  dis-h">
           <div class="dis-v left">
                <span> 欢迎~ </span>
               <span> VUE 新世界 </span>
           </div>
           <div class="dis-v right">
               <div class="username dis-h">
                   <el-input placeholder="请输入用户名"/>
               </div>
               <div class="pwd dis-h">
                    <el-input type="password" placeholder="请输入密码"/>
               </div>
               <div class="btn dis-h">
                   <el-button size="large"  style="width:220px;background-color:#626aef;color:#fff;font-weight:bold; ">登录</el-button>             
                </div>
               
               </div>   
       </div>
   </div>
</template>
<script setup>
</script>
<style >
.login-container{
   width: 100vw;
   height: 100vh;
   background-image: url('../assets/background.jpeg');
   
   align-items: center;
   justify-content: center;
   background-repeat: no-repeat; /* 背景图片不重复 */    
   background-size: cover; /* 背景图片覆盖整个div区域 */
   background-position: center; /* 背景图片居中显示 */
}
.login-form{
   width: 600px;
   height: 300px;
   /* background-color: red; */
   
}
.login-form .left{
   width: 50%;
   height: 100%;
   align-items: left;
   justify-content: center;
   font-size: 1.6rem;
   font-weight: bold;
   background:linear-gradient(to right bottom,rgba(136,209,234,0.80) 5%,rgba(215,193,187,0.80) 100% );
   color: #fff;
   text-indent:1rem;
}
.login-form .right{
   width: 50%;
   height: 100%;
   background-color: rgba(255, 255, 255, 0.90);
   align-items: center;
   justify-content: center;
}
.login-form .username,.pwd,.btn{
   padding: 0.5rem 0; 
  
}

/*水平排列子元素*/
.dis-h{
display: flex;
}
/*垂直排列子元素*/
.dis-v{
display: flex;
flex-direction: column;
}

</style>

二:修改路由:

三.修改App.vue文件,注释掉导航信息

四:刷新网页查看效果

四.前端登录并跳转逻辑处理

输入用户名、密码点击登录,成功可以跳转到其他页面

代码处理如图所示:

修改后的LoginView.vue代码:

javascript 复制代码
<template>
    <div class="login-container dis-h">
       <div class="login-form  dis-h">
           <div class="dis-v left">
                <span> 欢迎~ </span>
               <span> VUE 新世界 </span>
           </div>
           <div class="dis-v right">
               <div class="username dis-h">
                   <el-input placeholder="请输入用户名" v-model="loginform.username"/>
               </div>
               <div class="pwd dis-h">
                    <el-input type="password" placeholder="请输入密码" v-model="loginform.pwd"/>
               </div>
               <div class="btn dis-h">
                   <el-button size="large"  style="width:220px;background-color:#626aef;color:#fff;font-weight:bold; "
                   @click="commit">登录</el-button>             
                </div>
               
               </div>   
       </div>
   </div>
</template>
<script setup>
import {ref} from "vue"
import router from '@/router';
import { ElMessage } from 'element-plus';

var loginform=ref({
    username:"",
    pwd:""
})

var commit=function(){
    
  if(loginform.value.username=="123"&&loginform.value.pwd=="111"){
    ElMessage.success("YES,成功啦啦啦啦啦!");
    router.replace("./about")
  }
  else{
    ElMessage.error("Sorry,失败!");
  }
}


</script>
<style >
.login-container{
   width: 100vw;
   height: 100vh;
   background-image: url('../assets/background.jpeg');
   
   align-items: center;
   justify-content: center;
   background-repeat: no-repeat; /* 背景图片不重复 */    
   background-size: cover; /* 背景图片覆盖整个div区域 */
   background-position: center; /* 背景图片居中显示 */
}
.login-form{
   width: 600px;
   height: 300px;
   /* background-color: red; */
   
}
.login-form .left{
   width: 50%;
   height: 100%;
   align-items: left;
   justify-content: center;
   font-size: 1.6rem;
   font-weight: bold;
   background:linear-gradient(to right bottom,rgba(136,209,234,0.80) 5%,rgba(215,193,187,0.80) 100% );
   color: #fff;
   text-indent:1rem;
}
.login-form .right{
   width: 50%;
   height: 100%;
   background-color: rgba(255, 255, 255, 0.90);
   align-items: center;
   justify-content: center;
}
.login-form .username,.pwd,.btn{
   padding: 0.5rem 0; 
  
}

/*水平排列子元素*/
.dis-h{
display: flex;
}
/*垂直排列子元素*/
.dis-v{
display: flex;
flex-direction: column;
}

</style>

修改后的AboutView.vue代码

javascript 复制代码
<template>
  <div class="about">
    <h1>This is an about page</h1>
  </div>
  <div>
    <el-button @click="loginOut">退出登录</el-button>
  </div>
</template>

<script setup>
import router from '@/router';


var loginOut=function(){
  router.replace("/")
}

</script>
相关推荐
C_心欲无痕16 小时前
前端实现水印的两种方式:SVG 与 Canvas
前端·安全·水印
尾善爱看海19 小时前
不常用的浏览器 API —— Web Speech
前端
美酒没故事°19 小时前
vue3拖拽+粘贴的综合上传器
前端·javascript·typescript
jingling55520 小时前
css进阶 | 实现罐子中的水流搅拌效果
前端·css
zhengxianyi5151 天前
只需3句让Vue3 打包部署后通过修改配置文件修改全局变量——实时生效
vue.js·前后端分离·数据大屏·ruoyi-vue-pro优化
悟能不能悟1 天前
前端上载文件时,上载多个文件,但是一个一个调用接口,怎么实现
前端
可问春风_ren1 天前
前端文件上传详细解析
前端·ecmascript·reactjs·js
羊小猪~~1 天前
【QT】--文件操作
前端·数据库·c++·后端·qt·qt6.3
ltqshs1 天前
vscode离线插件下载-vscode编译嵌入式C语言配置
c语言·ide·vscode
晚风资源组1 天前
CSS文字和图片在容器内垂直居中的简单方法
前端·css·css3