1、在data中获取
data() {
return {
screenWidth: document.body.clientWidth, // 屏幕宽度
screenHeight: document.body.clientHeight, // 屏幕高度
}
}
2、在mounted函数中获取
mounted() {
window.screenWidth = document.body.clientWidth;
window.screenHeight = document.body.clientHeight;
this.screenWidth = window.screenWidth;
this.screenHeight = window.screenHeight;
console.log(window.screenWidth);
console.log(window.screenHeight);
console.log(this.screenWidth);
console.log(this.screenHeight);
}