I am currently working on a versatile component that is designed to receive different types of backend data. Within my code, I have implemented a switch statement with one condition being:
case 'Bases':
let bases = variant[tableName][colValue].map((base) => {
return `<div class="base b${base.strongestIndication}">${base.name}</div>`
})
return bases.join('')
My template utilizes v-html, which results in the creation of 3 divs each with classes "base", "b1", "b2", and "b3". These classes are correctly applied when inspecting the elements on the website.
In the CSS styles, I have specified rules for these classes (such as background-color, border-radius, etc.), but they do not seem to be taking effect.
I suspect that this issue may be related to the fact that the CSS is being applied before the divs are created programmatically, but I am uncertain.
How can I ensure that these dynamically created tags are styled properly using JavaScript?
(Additionally, I acknowledge the potential risks associated with using v-html, so if you have alternative suggestions for this implementation, I am open to hearing them)