简体   繁体   中英

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 .

Then an image in option tag with item.image but this doesn't work

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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