怎么用vue获取屏幕的宽度
本篇內容主要講解“怎么用vue獲取屏幕的寬度”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“怎么用vue獲取屏幕的寬度”吧!
1.使用document.documentElement方法獲取屏幕的寬高
windowWidth: document.documentElement.clientWidth, //獲取屏幕寬度
windowHeight: document.documentElement.clientHeight, //獲取屏幕高度
2.在watch中實時監聽屏幕寬高
watch: {
windowHeight (val) {
let that = this;
console.log("實時屏幕高度:",val, that.windowHeight );
},
windowWidth (val) {
let that = this;
console.log("實時屏幕寬度:",val, that.windowHeight );
}
},
3.使用mounted函數獲取屏幕寬高
mounted() {
var that = this;
window.onresize = () => {
return (() => {
window.fullHeight = document.documentElement.clientHeight;
window.fullWidth = document.documentElement.clientWidth;
that.windowHeight = window.fullHeight; //獲取屏幕高度
that.windowWidth = window.fullWidth; //獲取屏幕寬度
})()
};
},
Vue的優點
Vue具體輕量級框架、簡單易學、雙向數據綁定、組件化、數據和結構的分離、虛擬DOM、運行速度快等優勢,Vue中頁面使用的是局部刷新,不用每次跳轉頁面都要請求所有數據和dom,可以大大提升訪問速度和用戶體驗。
總結
以上是生活随笔為你收集整理的怎么用vue获取屏幕的宽度的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CRM Fiori my note应用的
- 下一篇: php web的概念是什么