鍍金池/ 問答/HTML5  網(wǎng)絡(luò)安全  HTML/ 怎么給vue-cli打包的 頁面body元素添加樣式呢?

怎么給vue-cli打包的 頁面body元素添加樣式呢?

圖片描述

頁面被擠壓了 怎么才能不被擠壓上去

<template>
<div class="login">

<div class="logo">
  <div class="pic"></div>
</div>
<div class="inp">
  <div class="number">
    <i class="icon"></i>
    <input  type="text" ref="mobile" v-model="loginData.mobile" placeholder="請輸入手機(jī)號" >
  </div>
  <div class="code">
    <i class="icon"></i>
    <input type="text" v-model="loginData.authCode" placeholder="請輸入驗(yàn)證碼">
    <div class="codetime">
      <button @click="getCode" class="code-btn" :disabled="!show">
        <span v-show="show">獲取驗(yàn)證碼</span>
        <span v-show="!show" class="count">{{count}}秒后可以從新獲取</span>
      </button>
    </div>
    
  </div>
</div>
<div class="agree">
  <label for="select" class="radio" @touchstart="touch">
            <img ref="img1" src="../assets/svg/icon_ccc.svg"  width="18" style="vertical-align: -3px;display: none" >
            <img ref="img2" src="../assets/svg/icon_agree.svg" width="18" style="vertical-align: -3px;">
            我已經(jīng)閱讀并同意<span>棱鏡APP用戶協(xié)議</span>
        </label>
</div>
<div class="button">
  <mt-button type="primary" @click="login" :disabled="!loginData.mobile || !loginData.authCode">進(jìn)入棱鏡</mt-button>
</div>
<!-- <button @click="register">進(jìn)入注冊頁</button> -->

</div>
</template>

<script>
import { Toast } from "mint-ui";
export default {
data() {

return {
  loginData: {
    mobile: "",
    authCode: ""
  },

  TIME_COUNT: 5,
  show: true,
  count: "",
  timer: null,
  flag: true
};

},
created() {},
methods: {

// 選擇是否同意協(xié)議--
touch() {
  console.log(this.flag);
  if (this.flag) {
    this.flag = false;
    this.$refs.img1.style.display = "inline-block";
    this.$refs.img2.style.display = "none";
  } else {
    this.$refs.img1.style.display = "none";
    this.$refs.img2.style.display = "inline-block";
    this.flag = true;
  }
},
// 選擇是否同意協(xié)議--
login() {
  console.log(this.loginData);
  let url =
    "http://dsn.apizza.cc/mock/33a3028a1c490faf003f2b6196f2cc92/data1"; /** 登錄(發(fā)送 手機(jī)號 和 驗(yàn)證碼) */
  this.$http.post(url, this.loginData).then(
    function(res) {
      if (res.body.code === 1) {
        this.$router.push({ name: "register" });
      } else if (res.body.code === 0) {
        this.$router.push({ name: "list" });
      } else {
        Toast("密碼錯(cuò)誤");
      }
    },
    function(res) {
      Toast("登錄錯(cuò)誤");
    }
  );
},
register() {
  this.$router.push({ path: "/register" });
},
// 獲取驗(yàn)證碼---
getCode() {
  this.mobile = this.$refs.mobile.value;
  let url =
    "http://dsn.apizza.cc/mock/4c0fdc85afc6c0f01766671f4f13ace3/plus/sms_vcode"; /**  獲取驗(yàn)證碼 */
  this.$http.post(url, { mobile: this.mobile }).then(
    function(res) {
      Toast({ message: "成功獲取驗(yàn)證碼", position: "bottom" });
    },
    function(res) {
      Toast("發(fā)送錯(cuò)誤");
    }
  );

  Toast("驗(yàn)證碼已經(jīng)發(fā)送到" + this.mobile + "這個(gè)手機(jī)號上");
  if (!this.timer) {
    this.count = this.TIME_COUNT;
    this.show = false;
    this.timer = setInterval(() => {
      if (this.count > 0 && this.count <= this.TIME_COUNT) {
        this.count--;
      } else {
        this.show = true;
        clearInterval(this.timer);
        this.timer = null;
      }
    }, 1000);
  }
}
// 獲取驗(yàn)證碼---

}
};
</script>
<style lang="less" scoped>
.login {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: url("../../static/imgs/bgi.png") no-repeat;
background-size: cover;
.logo {

.pic {
  width: 16vw;
  height: 14vh;
  line-height: 70px;
  text-align: center;
  margin: 14vh auto;
  background: url("../../static/imgs/logo@3x.png") no-repeat;
  background-size: 100% 100%;
}
.word {
  font-size: 25px;
  font-weight: bold;
  text-align: center;
}

}
.inp {

.number {
  //   border:1px solid red;
  font-size: 0;
  margin: 10px auto;
  width: 68vw;
  height: 7vh;
  border-bottom: 1px solid #ccc;
  box-sizing: border-box;
  padding: 10px;
  .icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    background: url("../../static/imgs/user@3x.png") no-repeat;
    background-size: 100% 100%;
    vertical-align: sub;
  }
  > input {
    background: none;
    outline: none;
    border: 0px;
    width: 150px;
    font-size: 14px;
    padding: 0 10px;
    color: #fff;
  }
}
.code {
  //   border:1px solid red;

  font-size: 0;
  text-align: center;
  margin: 10px auto;
  margin-top: 40px;
  width: 68vw;
  height: 7vh;
  border-bottom: 1px solid #ccc;
  box-sizing: border-box;
  .icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    background: url("../assets/imgs/mima@3x.png") no-repeat;
    background-size: 100% 100%;
    vertical-align: sub;
  }
  input {
    height: 25px;
    width: 25vw;
    background: none;
    outline: none;
    border: 0px;
    font-size: 14px;
    padding: 0 10px;
    color: #fff;
  }
  .codetime {
    display: inline-block;
    button {
      outline: none;
      border: 0px;
      width: 28vw;
      height: 4vh;
      padding: 0;
      border-radius: 14vw;
    }
  }
}

}
.agree {

margin: 30px auto;
width: 100%;
height: 30px;
line-height: 30px;
text-align: center;
color: #fff;
font-size: 13px;
span {
  color: #48a1e3;
  text-decoration: underline;
}

}
.button {

text-align: center;
> button {
  outline: none;
  border: 0px;
  padding: 0;
  width: 68vw;
  height: 7vh;
  border-radius: 34vw;
  font-size: 5vw;
  font-weight: bold;
  color: #fff;
  background-color: #48a1e3;
}

}
}
</style>

回答
編輯回答
心夠野

使用vh作為高度的單位,這是后遺癥,軟鍵盤彈出后,整個(gè)頁面高度發(fā)生變化。比如說,原來的視窗高度為1334px,那么14vh的高度就是1334 x 0.14 = 186.76(px) ; 小鍵盤彈出來后高度變?yōu)?800px, 那么14vh的高度只有 800 x 0.14 = 112(px)了;但是vw卻沒有改變,所以你看到的視圖是變形的。
解決方案: 統(tǒng)一使用vw布局;

建議參考分享手淘過年項(xiàng)目中采用到的前端技術(shù)對vw進(jìn)行兼容處理

2018年7月6日 02:37
編輯回答
心夠野

我一般是這么設(shè)置

login:{
    min-height:100%;
}
一般都是頁面被頂上去(IOS),你這還能出現(xiàn)頁面被擠壓
2017年2月10日 18:10