We are working with Vue and the client has asked us for a button that allows him to choose the theme that he prefers.
The point is, I need to dynamically load the css file that corresponds to each theme.
I have tried this: How to load css file dynamically but I haven't made it work.
My code:
Account.vue:
multiselect(
v-model="theme",
:placeholder="$t('Select')",
label="name",
track-by="code",
:showLabels="false"
:options="themes",
:multiple="false",
:taggable="false",
:selectLabel="$t('SelectLabel')",
.columns
.column.has-text-centered
button.button(@click='sendData, appendFile', :disabled="!language || !rol || !theme") {{ $t('Save') }}
JS:
data() {
return {
theme: null,
themes: [
{ name: 'Default', code: 'def' },
{ name: 'Montich', code: 'mont' },
],
};
},
methods: {
sendData() {
this.$store.dispatch('THEME_SELECT', this.theme.code).then(() => {
});
appendFile() {
const file = document.createElement('link');
file.rel = 'stylesheet';
file.href = 'assets/css/montich.css';
file.head.appendChild(file);
},
},
Now some prints: ...Files ...Network and view Thanks in advance!