vue浏览器与body宽高获取

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>vue浏览器与body宽高获取</title>
  <script src="https://cdn.bootcss.com/vue/2.4.2/vue.js"></script>
  <style>
    body{border:10px solid red}
  </style>
</head>
<body>
  <div id="app">
        <p>body宽度(不包括边线):<span>{{count1}}</span></p>
        <p>body高度(不包括边线):<span>{{count2}}</span></p>
        <p>body宽度(包括边线的宽):<span>{{count1_1}}</span></p>
        <p>body高度(包括边线的宽):<span>{{count2_2}}</span></p>
        <p>浏览器可视区域宽度:<span>{{count3}}</span></p>
        <p>浏览器可视区域高度:<span>{{count4}}</span></p>
        <p>屏幕分辨率的宽:<span>{{count5}}</span></p>
        <p>屏幕分辨率的高:<span>{{count6}}</span></p>
        <p>屏幕可用工作区宽度:<span>{{count7}}</span></p>
        <p>屏幕可用工作区高度:<span>{{count8}}</span></p>
  </div>
</body>
<script>
  var vm = new Vue({
    el: '#app',
    data: {
        count1: document.body.clientWidth,
        count2:document.body.clientHeight,
        count1_1:document.body.offsetWidth,
        count2_2:document.body.offsetHeight,
        count3:document.documentElement.clientWidth,
        count4:document.documentElement.clientHeight,
        count5:window.screen.width,
        count6:window.screen.height,
        count7:window.screen.availWidth,
        count8:window.screen.availHeight
    },
    methods:{
        getScreenSize() {
            window.onresize = () => {
              this.count1 = document.body.clientWidth;
              this.count2 = document.body.clientHeight;
              this.count1_1 = document.body.offsetWidth;
              this.count2_2 = document.body.offsetHeight;
              this.count3 = document.documentElement.clientWidth;
              this.count4 = document.documentElement.clientHeight;
              this.count5 = window.screen.width;
              this.count6 = window.screen.height;
              this.count7 = window.screen.availWidth;
              this.count8 = window.screen.availHeight;
            };
        },
    },
    mounted: function() {
        this.getScreenSize();
    },
  })
</script>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值