简体   繁体   English

VueJS数据绑定对象样式不起作用

[英]VueJS data-bind object styling not working

I'm playing around in VueJS styling with v-bind, I noticed something particular, when I switch from v-bind inline styling to v-bind object styling. 当我从v-bind内联样式转换为v-bind对象样式时,我在使用v-bind的VueJS样式中玩耍,我注意到一些特别之处。 The inline style works fine. 内联样式效果很好。 However, when I create an object in Vue, and try to style with the object, the width and height do not style, even though the rest does. 但是,当我在Vue中创建对象并尝试使用该对象设置样式时,即使其余部分都设置了宽度和高度,也不会设置样式。

I realize this is most likely a syntax error, I tried adding quotes around value of height & width. 我意识到这很可能是语法错误,我尝试在height&width的值周围添加引号。

<span :style="progbar">80%</span>

// styling:

progbar:{
   height: 20,
   width: 800,  
   backgroundColor: 'red',
   color: 'white',
   fontSize: '30px'

   }

I expect to see a bar of 800 width, however that is not showing up and I can't figure out why. 我希望看到宽度为800的条,但是条没有显示出来,我也不知道为什么。 The full code is at: https://jsfiddle.net/totoro183/nho1jv37/51/ 完整代码位于: https : //jsfiddle.net/totoro183/nho1jv37/51/

Use <div :style="progbar">80%</div> instead of span . 使用<div :style="progbar">80%</div>代替span It works with div and no with span because span is an inline element. 它适用于div ,不适用于span因为span是一个内联元素。 It has no width or height. 它没有宽度或高度。

You need to surround width and height values with ' ' 您需要用''包围宽度和高度值

progbar:{
   height: '20px',
   width: '800px',
   ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM