Vue.js——登录界面实现插入背景

效果图

在这里插入图片描述

插入背景图片

样式

制作样式
因为我顶部设置了导航栏,所有高度只设置了85%

.background_style{
width:100%;
height:85%;
position:fixed;
background-size:100% 100%;
background-repeat: no-repeat;
background-image: url("../../assets/background_1.jpg");
}

引用

因为是背景图片,所有要在最外层div引用

 <div  class="background_style">

登录实现

引入Element UI

Element UI

通过npm安装

执行此命令

npm i element-ui -S

然后再main.js中导入Element UI库

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);
通过引入样式库

直接在需要使用Element UI组件的页面声明即可

<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>

实现

<el-form  status-icon   label-width="50px" label-position="left" class="login-page" >
      <h2 class="login_Title">账号登录</h2>
      <el-form-item label="账号" prop="username" >
        <el-input type="text"  v-model="username" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input type="password" v-model="password" autocomplete="off" show-password></el-input>
      </el-form-item>
      <el-form-item class="button_center">
        <el-button type="primary" @click="LoginNleCloud" style="width:50%;" >提交</el-button>
      </el-form-item>
    </el-form>
双向绑定账号密码
v-model="username"
v-model="password"

定义字段

 data(){
    return{
      password: "",
      username: "",
  }
设置点击事件

Es6缩写

@click="LoginNleCloud" 

普通写法

v-on:click="LoginNleCloud"

需要在methods才能定义方法
然后对账户密码进行判断
如果成功则跳转路由,失败则提醒用户

methods:{
    LoginNleCloud(){
      if (this.username === "hntdiot" && this.password === "hntdiot")
      {
        window.nleApi = new NLECloudAPI()
        const res = window.nleApi.userLogin(this.username,this.password,true)
        res.completed(function (res) {
          window.Flag = true
          //alert("Success!")
          console.log(res)
        })
        if ( window.Flag === true){
          this.$router.push('/console')
          console.log(window.Flag)
        }
      }else {
        alert("账户或者密码错误!")
      }
    }

尾言

初学Vue.js,书写此文,以备此后温故而习之

  • 14
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FranzLiszt1847

嘟嘟嘟嘟嘟

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值