Prevent unnecessary switch
parent
032a6a8355
commit
9e13aaf342
2
app.vue
2
app.vue
|
@ -22,13 +22,11 @@ export default {
|
|||
},
|
||||
mounted() {
|
||||
this.themeChangeListener = (event) => {
|
||||
if (event.theme !== this.$appState.theme) {
|
||||
this.$primevue.changeTheme(this.$appState.theme, event.theme, 'theme-link', () => {
|
||||
this.$appState.theme = event.theme;
|
||||
this.$appState.darkTheme = event.dark;
|
||||
EventBus.emit('theme-change-complete', { theme: event.theme, dark: event.dark });
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
EventBus.on('theme-change', this.themeChangeListener);
|
||||
|
|
|
@ -157,6 +157,7 @@ export function usePrimeVue() {
|
|||
}
|
||||
|
||||
function switchTheme(currentTheme, newTheme, linkElementId, callback) {
|
||||
if (currentTheme !== newTheme) {
|
||||
const linkElement = document.getElementById(linkElementId);
|
||||
const cloneLinkElement = linkElement.cloneNode(true);
|
||||
const newThemeUrl = linkElement.getAttribute('href').replace(currentTheme, newTheme);
|
||||
|
@ -173,6 +174,7 @@ function switchTheme(currentTheme, newTheme, linkElementId, callback) {
|
|||
});
|
||||
linkElement.parentNode && linkElement.parentNode.insertBefore(cloneLinkElement, linkElement.nextSibling);
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
install: (app, options) => {
|
||||
|
|
Loading…
Reference in New Issue