【CSS】怎么给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="请输入手机号" >
</div>
<div class="code">
<i class="icon"></i>
<input type="text" v-model="loginData.authCode" placeholder="请输入验证码">
<div class="codetime">
<button @click="getCode" class="code-btn" :disabled="!show">
<span v-show="show">获取验证码</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;">
我已经阅读并同意<span>棱镜APP用户协议</span>
</label>
</div>
<div class="button">
<mt-button type="primary" @click="login" :disabled="!loginData.mobile || !loginData.authCode">进入棱镜</mt-button>
</div>
<!-- <button @click="register">进入注册页</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: {
// 选择是否同意协议--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;
}
},
// 选择是否同意协议--
login() {
console.log(this.loginData);
let url =
"http://dsn.apizza.cc/mock/33a3028a1c490faf003f2b6196f2cc92/data1"; /** 登录(发送 手机号 和 验证码) */
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("密码错误");
}
},
function(res) {
Toast("登录错误");
}
);
},
register() {
this.$router.push({ path: "/register" });
},
// 获取验证码---
getCode() {
this.mobile = this.$refs.mobile.value;
let url =
"http://dsn.apizza.cc/mock/4c0fdc85afc6c0f01766671f4f13ace3/plus/sms_vcode"; /** 获取验证码 */
this.$http.post(url, { mobile: this.mobile }).then(
function(res) {
Toast({ message: "成功获取验证码", position: "bottom" });
},
function(res) {
Toast("发送错误");
}
);
Toast("验证码已经发送到" + this.mobile + "这个手机号上");
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);
}
}
// 获取验证码---
}
};
</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作为高度的单位,这是后遗症,软键盘弹出后,整个页面高度发生变化。比如说,原来的视窗高度为1334px,那么14vh的高度就是1334 x 0.14 = 186.76(px) ; 小键盘弹出来后高度变为 800px, 那么14vh的高度只有 800 x 0.14 = 112(px)了;但是vw却没有改变,所以你看到的视图是变形的。
解决方案: 统一使用vw布局;
建议参考分享手淘过年项目中采用到的前端技术对vw进行兼容处理
回答:
我一般是这么设置
login:{ min-height:100%;
}
一般都是页面被顶上去(IOS),你这还能出现页面被挤压
以上是 【CSS】怎么给vue-cli打包的 页面body元素添加样式呢? 的全部内容, 来源链接: utcz.com/a/156058.html