I have a simple Vue.js component in which I render a piece of HTML:
...
<div class="sml-button" v-on:click="toggleButton()" v-html="button"></div>
...
On click, the toggleButton() method updates the button data:
toggleButton: function() {
if (this.shouldBeShown) {
this.button = 'show less';
} else {
this.button = '<span>...</span>show more';
}
}
Notice the <span></span> element in the else.
What is happening, is I am unable to style this span element within my component - presumably because it's dynamically created:
<style lang="sass" scoped>
.sml-button {
color: #4390ca;
font-size: 14px;
font-family: latoregular, Helvetica, Arial, sans-serif;
span {
color: #3f3f3f; /* THIS WON'T BE COMPILED */
}
}
</style>
The parent class (.sml-button) has its styles. The child span doesn't.
How do I apply styles on a dynamically added HTML element inside of a Vue.js component?