简体   繁体   English

如何在vue js的选择选项中设置动态样式

[英]how to set dynamic style in select option in vue js

<select v-model="selectcurrency"
   @change="[get(),ready(),setcookie()]"
   class="selectpicker"
   data-live-search="true"
   data-width="120px"
   style="width: 80px;">
      <option v-for="item in currency" :value="item"
         :style="color:'red'" //this style>
            @{{item.symbol}} -- @{{ item.name }}
      </option>
</select>

I need the option tag with item.count where it will color it black if item.count > 0 and color it red if item.count < 0 .我需要带有item.countoption标签,如果item.count > 0它将其着色为黑色,如果item.count < 0将其着色为红色。

Then an image in option tag with item.image but this doesn't work然后是带有item.imageoption标签中的图像,但这不起作用

data-subtext="<img src='item.icon' class='img img-circle img-thumbnail'>"

You can use Class And Style Bindings with Ternary Operator您可以将类和样式绑定三元运算符一起使用

In your situation:在你的情况下:

 <option v-for="item in currency" :value="item" :style="{ color: item.count > 0 ? 'red' : 'black'" //use like this> @{{item.symbol}} -- @{{ item.name }} </option>

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

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