首页 > 其他分享 >Vue 实时获取屏幕宽高

Vue 实时获取屏幕宽高

时间:2022-12-07 16:22:06浏览次数:39  
标签:Vue val 宽高 实时 window windowHeight 屏幕 document

export default {
    name: 'page-index',
    data(){
        return{
            windowWidth: document.documentElement.clientWidth,  //实时屏幕宽度
            windowHeight: document.documentElement.clientHeight,   //实时屏幕高度
        }
    },    
    methods: {
    },
    // <!--在watch中监听实时宽高-->
    watch: {
      windowHeight (val) {
        let that = this;
        console.log("实时屏幕高度:",val, that.windowHeight );
      },
      windowWidth (val) {
        let that = this;
        console.log("实时屏幕宽度:",val, that.windowHeight );
      }
    },

    mounted() {
        var that = this;
        // <!--把window.onresize事件挂在到mounted函数上-->
        window.onresize = () => {
            return (() => {
              window.fullHeight = document.documentElement.clientHeight;
                window.fullWidth = document.documentElement.clientWidth;
              that.windowHeight = window.fullHeight;  // 高
              that.windowWidth = window.fullWidth; // 宽
            })()
          };
    },
}

 

标签:Vue,val,宽高,实时,window,windowHeight,屏幕,document
From: https://www.cnblogs.com/linweimu/p/16963460.html

相关文章

  • vue el-input只能输入正整数 替换e - + 等
      示例:输入分页页数,每页显示条数<el-inputtype="number"class="resNums"v-model="item.resNums":min="1":max="500"step="10"placeholder="结果显示条数"onK......
  • web技术分享| 图片上传与图片裁剪结合 vue3
    需求:上传的图片限制长宽相同;只能上传图片;图片大小限制500k当前项目仅需要上传的图片信息项目组件使用裁剪:vue-cropperimport"vue-cropper/dist/index.c......
  • Vue基本语法
    v-bind我们成功创建了第一个Vue程序,看起来跟渲染一个字符串模板非常类似。但是Vue在背后做了大量工作。现在数据和DOM已经被建立了关联,所有东西都是响应式的。我们在......
  • vue i18n _ctx.$t is not a function
     一、问题Uncaught(inpromise)TypeError:_ctx.$tisnotafunctionatSelect.vue:51:95atrenderFnWithContext(runtime-core.esm-bundler.js:852:21)......
  • 手写vue-router核心原理
    最近也在观察vue3新特性,抽空玩一玩嵌套路由的vue-router,直接上代码项目目录结构代码展示app.vue<template><divid="app"><div><router-linkto="/"......
  • 创建Vue项目
    前期准备:安装node.js(node-v检查是否安装)安装vue-cli脚手架(使用淘宝镜像,然后运行npminstall-gvue-cli安装脚手架,vue-V检查是否安装)一、基本创建项目操作1、初始......
  • 使用vue深度选择器修改ElementUI组件内样式
    例子:el-collapse标签修改子组件样式在带有scoped属性的style中书写样式时,无法作用影响到子组件中的样式,此时我们会使用到deep深度选择器,来解决此问题,我们在使用less预处理......
  • vscode中引用vue3时红色提示
    从GitHub上下载了一个前端项目学习,用vscode打开。“vue3+vite”在vscode控制台执行npminstall,安装所需要的各种包。这个时候可以用npmrundev,启动项目。但是vs......
  • Vue中的diff算法深度解析
    模板tamplate经过parse,optimize,generate等一些列操作之后,把AST转为renderfunctioncode进而生成虚拟VNode,模板编译阶段基本已经完成了,那么这一章,我们来探讨一下Vue中的一......
  • Vue3必会技巧-自定义Hooks
    Vue3自定义Hooks定义:个人理解:一些可复用的方法像钩子一样挂着,可以随时被引入和调用以实现高内聚低耦合的目标,应该都能算是hook;为什么Vue3要用自定义Hook?:结论:就是为了......