vue屏幕长宽自适应

vue 自适应屏幕的宽高度

 

在这里插入图片描述
通过定义属性进行双向绑定改变body的高度,watch监测窗口大小变化时触发,改变属性值达到预期效果,代码贴上

 

<template>
	<div class="bgColor" :style="'height:'+fullHeight+'px;'">
		<div class="login-wrap">
			<h1 class="login-title">评测管理员</h1>
			<div class="login-type-wrap">
				<router-link to="/login" class="logintype">登录</router-link>
				<router-link to="/registered" class="logintype">注册</router-link>
			</div>
			<router-view></router-view>
		</div>
	</div>
</template>
<script>
	export default{
		name:"Login",
		data () {
			return {
				fullHeight: document.documentElement.clientHeight
			}
		},
		watch: {
			fullHeight (val) {//监控浏览器高度变化
				if(!this.timer) {
					this.fullHeight = val
					this.timer = true
					let that = this
					setTimeout(function (){
						that.timer = false
					},400)
				}
				
			}
		},
		mounted () {
			this.get_bodyHeight()
		},
		methods :{
			get_bodyHeight () {//动态获取浏览器高度
				const that = this
				window.onresize = () => {
					return (() => {
						window.fullHeight = document.documentElement.clientHeight
						that.fullHeight = window.fullHeight
					})()
				}
			}
		}
	}
</script>

<style scoped>
@import '../../assets/style/auth/loginOrReg.css';
</style>

 

对于整个适应的背景图不让其平铺 ,宽高100%就ok

	background: url('../image/2.jpg') no-repeat center;
    background-size: 100% 100%;

 

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值