Having some unexpected issues while trying to implement a style conditional for items in Vuejs.
I have come across Stack Overflow posts on how to use a ternary, either through an interpolated string or a computed style object. I've attempted both methods but neither seem to be working correctly.
Here's the code snippet:
<div
:class="{'radar__container':true,'inactive':inactive}"
:style="[inactive ? {getStyleRadarContainerInactive} : {getStyleRadarContainer}]"
>
To apply this style:
computed: {
getStyleRadarContainer: function(){
let styleRadarContainer = {
left: this.radarItem.posX*100 + '%',
top: this.radarItem.posY*100 + '%',
transform: 'translate(-50%,-50%) scale(' + this.radarItem.scale + ')',
opacity: this.radarItem.opacity,
}
return styleRadarContainer;
},
getStyleRadarContainerInactive: function(){
let styleRadarContainerInactive= {
left: this.radarItem.posX*100 + '%',
top: this.radarItem.posY*100 + '%',
transform: 'translate(-50%,-50%) scale(0)',
opacity: this.radarItem.opacity,
}
return styleRadarContainerInactive;
},
}
Even though the intention is for each item to scale down (due to the scale(0) in the opacity property), the style attribute fails to render at all. I also experimented with an inline ternary on the style prop (as the scale is the only changing factor between the two properties):
transform: 'translate(-50%,-50%) ' + inactive ? 'scale(' + radarItem.scale + ')' : 'scale(0)',
What could be causing this issue?