data(){
return {
topHeight: 300,
clientHeight: 0
}
}
mounted(){
this.clientHeight=`${document.documentElement.clientHeight}`
let that=this
window.onresize=function(){
that.clientHeight=`${document.documentElement.clientHeight}`
if(that.clientHeight>=1080){
that.topHeight=400
}else{
that.topHeight=300
}
}
}
<div class="m-top" :style="{'height' : topHeight+'px'}"></div>
相关语法:1.`${}` 模板字符串 2.window.onresize当浏览器被重置大小时执行Javascript代码
3. :style使用方法:https://www.cnblogs.com/weichenzhiyi/p/8406021.html
tip:其他动态样式问题也可以考虑通过此方案解决