I have set of buttons getting live probability odds of an event for the user to select.
The buttons get data from an api every minutes.
I want to disable the button if the probability is zero, I have a class suspended
, I want to add that class to the button.
This is the code I have so far.
event.vue
<div class="inply-coupon-odds-column">
<span data-id="118584087800" class="bvs-button-multi-sport " clicksource="in-play">{{tgames.home_odd }}</span>
<span data-id="118584088300" class="bvs-button-multi-sport " clicksource="in-play">{{tgames.neutral_odd }}</span>
<span data-id="118584088000" class="bvs-button-multi-sport" clicksource="in-play">{{tgames.away_odd }}</span>
</div>
This the json response from the api call.
{"neutral_odd":"0.00","home_odd":"1.38","away_odd":"2.75"}
Will appreciate any solutions.
2
Answers
you can easily achieve this by using Vue’s class binding.
Class binding allows you to dynamically add / remove css classes from the dom element. Refer to the Official Docs
Vue Class Binding
So in your case, you can try adding the
suspended
class by checking if the value is0
like soYou can achieve this requirement by using Dynamic
HTML class binding
.Just for demo, I am using iteration index as
data-id
nut you can replace it as per your requirement.Live Demo :