1.在数据中定义宽度和高度
data() {
            return {
                screenWidth: document.body.clientWidth, // 屏幕宽度
                screenHeight: document.body.clientHeight, // 屏幕高度
            }
        },
2、在mounted函数中获取数据
mounted() {
            const that = this;
            window.onresize = () => {
                return (() => {
                    window.screenWidth = document.body.clientWidth;
                    window.screenHeight = document.body.clientHeight;
                    that.screenWidth = window.screenWidth;
                    that.screenHeight = window.screenHeight;
                })()
            };
            console.log(this.screenWidth);
            console.log(this.screenHeight + '----');
        },
Logo

前往低代码交流专区

更多推荐