2023-03-03 07:02:10 +00:00
|
|
|
<template>
|
|
|
|
<DocSectionText v-bind="$attrs">
|
2023-10-15 10:00:23 +00:00
|
|
|
<p class="notification">
|
2023-03-03 07:02:10 +00:00
|
|
|
Solution below works however there is room for improvement. The upcoming styling api will greatly improve dynamic theme switching ability, eliminates the prerequisites with the introduction of CSS variables and dynamic imports.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Themes can be dynamically changed using the <i>PrimeVue.changeTheme</i> function. For this feature to work, there are two prerequisites. To begin with, the themes should be publicly available under the <i>public</i> folder in your project
|
|
|
|
by copying them from PrimeVue <i>resources/themes</i> folder. Second part is making the theme.css accessible via a link element so that the id of the link can be provided as the 3rd parameter to the <i>changeTheme</i> function.
|
|
|
|
</p>
|
|
|
|
</DocSectionText>
|
|
|
|
<DocSectionCode :code="code1" hideToggleCode importCode hideCodeSandbox hideStackBlitz />
|
|
|
|
<DocSectionCode :code="code2" hideToggleCode importCode hideCodeSandbox hideStackBlitz />
|
|
|
|
<DocSectionCode :code="code3" hideToggleCode importCode hideCodeSandbox hideStackBlitz />
|
|
|
|
<div class="doc-section-description">
|
|
|
|
<p>In a Vite based project like <a href="https://github.com/vuejs/create-vue">create-vue</a>, the link can be placed at index.html.</p>
|
|
|
|
</div>
|
2023-03-29 10:45:02 +00:00
|
|
|
<DocSectionCode :code="code4" hideToggleCode hideCodeSandbox hideStackBlitz />
|
2023-03-03 07:02:10 +00:00
|
|
|
<div class="doc-section-description">
|
|
|
|
<p><a href="https://nuxtjs.org/">Nuxt</a> applications can configure the link element using <i>nuxt.config.js</i>.</p>
|
|
|
|
</div>
|
|
|
|
<DocSectionCode :code="code5" hideToggleCode importCode hideCodeSandbox hideStackBlitz />
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
code1: {
|
|
|
|
basic: `
|
|
|
|
primevue.changeTheme(currentTheme: string, newTheme: string, linkElementId: string, callback: Function)
|
2023-10-15 09:38:39 +00:00
|
|
|
`
|
2023-03-03 07:02:10 +00:00
|
|
|
},
|
|
|
|
code2: {
|
|
|
|
basic: `
|
|
|
|
// Options API
|
2023-03-29 10:37:38 +00:00
|
|
|
this.$primevue.changeTheme('md-dark-indigo', 'md-light-indigo', 'theme-link', () => {});
|
2023-10-15 09:38:39 +00:00
|
|
|
`
|
2023-03-03 07:02:10 +00:00
|
|
|
},
|
|
|
|
code3: {
|
|
|
|
basic: `
|
|
|
|
// Composition API
|
|
|
|
import { usePrimeVue } from 'primevue/config';
|
|
|
|
|
|
|
|
const PrimeVue = usePrimeVue();
|
2023-03-29 10:37:38 +00:00
|
|
|
PrimeVue.changeTheme('md-dark-indigo', 'md-light-indigo', 'theme-link', () => {});
|
2023-10-15 09:38:39 +00:00
|
|
|
`
|
2023-03-03 07:02:10 +00:00
|
|
|
},
|
|
|
|
code4: {
|
2023-10-15 09:38:39 +00:00
|
|
|
basic: `
|
2024-01-18 03:51:37 +00:00
|
|
|
<link id="theme-link" rel="stylesheet" href="/themes/aura-light-green/theme.css">
|
2023-10-15 09:38:39 +00:00
|
|
|
`
|
2023-03-03 07:02:10 +00:00
|
|
|
},
|
|
|
|
code5: {
|
|
|
|
basic: `
|
|
|
|
export default defineNuxtConfig({
|
|
|
|
app: {
|
|
|
|
head: {
|
|
|
|
link: [
|
|
|
|
{
|
|
|
|
id: 'theme-link',
|
|
|
|
rel: 'stylesheet',
|
2024-01-18 03:51:37 +00:00
|
|
|
href: baseUrl + 'themes/aura-light-green/theme.css'
|
2023-03-03 07:02:10 +00:00
|
|
|
}
|
2023-10-15 09:38:39 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
`
|
2023-03-03 07:02:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|