首页

源码搜藏网

首页 > 开发教程 > js/jQuery教程 >

vue中的style样式如何动态绑定

创建时间:2022-04-21 09:31  

style样式如何动态绑定

(1) html中:

<div class="videoMa" ref="videoMa" style="width:100%;height:100%;">
<div id="playWnd" class="playWnd" :style="{width:videoBox.width+ 'px',height:videoBox.height+ 'px'}"></div>
</div>

(2) data中:

videoBox:{
   width:800,
   height:500,
  }

(3)mounted中:

 mounted() {
   this.videoBox.width=this.$refs.videoMa.offsetWidth;
   this.videoBox.height=this.$refs.videoMa.offsetHeight;
}

动态设置style样式

凡是有-的style属性名都要变成驼峰式,比如font-size要变成fontSize

除了绑定值,其他的属性名的值要用引号括起来,比如backgroundColor:'#00a2ff'而不是 backgroundColor:#00a2ff

html :style="{ color: activeColor, fontSize: fontSize + 'px' }"
html :style="{display:(activeName=='first''flex':'none')}"
html :style="[baseStyles, overridingStyles]"
html :style="[{display:(activeName=='first''flex':'none')},{fontSize:'20px'}]"
html :style="{color:(index==0conFontColor:'#ddd')}"
html :style="[{color:(index==0conFontColor:'#ddd')},{fontSize:'22px'}]"
html :style="{ display: ['-webkit-box', '-ms-flexbox', 'flex'] }"

以上为个人经验,希望能给大家一个参考,也希望大家多多支持源码搜藏网。

上一篇:vue实现数字动态翻牌器
下一篇:没有了

相关内容

热门推荐