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粉4818158972024-03-20 18:14:53
Try returning a style object instead of a string:
element.isResolve = { backgroundColor : element.isResolve ? 'green':'red' }