How to modify the color of text using the ternary operator in Vue?
P粉545218185
P粉545218185 2024-03-19 20:21:56
0
1
379

I want to change the text color coming from the endpoint. It only displays the value of the ternary operator ('backgroundColor:green) on the UI. Can anyone help me?

mainTrack() {
 this.axios
    .get(
      `${configObject.apiBaseUrl}/Maintenance/Company`,
      configObject.authConfig()
    )
    .then((res) => {
     this.maintainTrack= res.data;

     this.maintainTrack.forEach(element => {
       element.isResolve = element.isResolve== 'true' ? 'backgroundColor:green' :
        'backgroundColor:red'
            });
    })
    .catch((error) => {});
},

P粉545218185
P粉545218185

reply all(1)
P粉481815897

Try returning a style object instead of a string:

 element.isResolve = { backgroundColor : element.isResolve ? 'green':'red' }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template