vue窗口變化onresize詳解
更新時(shí)間:2024年08月10日 17:12:13 作者:xx_小熊
這篇文章主要介紹了vue窗口變化onresize,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
vue窗口變化onresize
div大小隨著窗口變化而變化
- 效果:


來看代碼
<template>
<div>
<div class="mask">
<div class="center" :style="{width:centerWidth*0.2+'px',height:centerHeight*0.5+'px'}">
<p>width:{{centerWidth}}</p>
<p>height:{{centerHeight}}</p>
</div>
</div>
</div>
</template><script>
export default {
data() {
return {
centerWidth: document.documentElement.clientWidth,
centerHeight: document.documentElement.clientHeight
};
},
mounted() {
window.onresize = () => {
this.centerWidth = document.documentElement.clientWidth;
this.centerHeight = document.documentElement.clientHeight;
};
}
};
</script>總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
實(shí)例詳解Vue項(xiàng)目使用eslint + prettier規(guī)范代碼風(fēng)格
這篇文章主要介紹了Vue項(xiàng)目使用eslint + prettier規(guī)范代碼風(fēng)格,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2018-08-08
vue 中this.$set 動(dòng)態(tài)綁定數(shù)據(jù)的案例講解
這篇文章主要介紹了vue 中this.$set 動(dòng)態(tài)綁定數(shù)據(jù)的案例講解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-01-01
vue前端HbuliderEslint實(shí)時(shí)校驗(yàn)自動(dòng)修復(fù)設(shè)置
這篇文章主要為大家介紹了vue前端中Hbulider中Eslint實(shí)時(shí)校驗(yàn)自動(dòng)修復(fù)設(shè)置操作過程,有需要的朋友可以借鑒參考下希望能夠有所幫助2021-10-10
解決vue2+vue-router動(dòng)態(tài)路由添加及路由刷新后消失問題
這篇文章主要介紹了解決vue2+vue-router動(dòng)態(tài)路由添加及路由刷新后消失問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08

