zhangyanpeng
2020-01-23 3f619a4e52661892789496f98b4e166470d29264
src/views/login.vue
@@ -1,8 +1,9 @@
<template>
  <div class="login">
  <div class="login" ref="hello_div">
    <!-- <div class="img-container">
      <img :src="loginImg" alt="">
    </div> -->
      <div class="login_" ref="logon_div">
    <el-form ref="loginForm" :model="loginForm" class="login-form" label-position="left">
      <el-form-item prop="loginName">
        <el-input
@@ -33,6 +34,7 @@
      <el-button :loading="loading" class="loginButton" type="primary" @click.native.prevent="handleLogin">登录</el-button>
    </el-form>
  </div>
  </div>
</template>
<script>
@@ -57,7 +59,30 @@
    }
  },
   mounted() {
      this.setWH();
   },
  methods: {
      setWH() {
         //获取屏幕宽度
         let hello_Width = this.$refs.hello_div.offsetWidth;
      //   let hello_Height = this.$refs.hello_div.offsetHeight;
         let hello_Height = document.documentElement.clientHeight;
         //获取登录元素宽度
         let logon_Width = this.$refs.logon_div.offsetWidth;
         let logon_Height = this.$refs.logon_div.offsetHeight;
         //设置登录元素的magin-left
         if (hello_Width>logon_Width) {
            let margin_left = (hello_Width - logon_Width)/2;
            this.$refs.logon_div.style['margin-left'] = margin_left + "px";
         }
         if (hello_Height>logon_Height) {
            let margin_top = (hello_Height - logon_Height)/2;
            this.$refs.logon_div.style['margin-top'] = margin_top + "px";
         }
      },
    // 忘记密码回调
   
    // 清除用户名
@@ -106,5 +131,10 @@
</script>
<style >
   .login_ {
      max-width: 350px;
      background-color: #f9f9fb;
      padding: 20px;
   }
</style>