Skip to content

Commit

Permalink
fix: 更改 element plus config设置方式,修复路由api模式下el api组件无法应用配置问题
Browse files Browse the repository at this point in the history
  • Loading branch information
yuntian001 committed Apr 10, 2023
1 parent f88a806 commit e5d8039
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<el-config-provider :locale="settingStore.elLocale" :size="settingStore.themeConfig.size">
<router-view v-slot="{ Component }">
<me-component :is="Component" done-progress close-loading="layout"></me-component>
</router-view>
</el-config-provider>
<router-view v-slot="{ Component }">
<me-component :is="Component" done-progress close-loading="layout"></me-component>
</router-view>
<setElGlobel v-if="showSetElGlobel"></setElGlobel>
</template>
<script setup lang="ts">
import { useSettingStore } from '@/store';
import { SizeEnum } from '@/dict/configEnum';
import SetElGlobel from './setElGlobel';
const settingStore = useSettingStore();
const htmlDom = document.getElementsByTagName('html')[0];
watchEffect(() => {
Expand All @@ -16,6 +16,14 @@ watchEffect(() => {
});
htmlDom.classList.add('me-' + settingStore.themeConfig.size);
});
const showSetElGlobel = ref(true);
watch(
() => [settingStore.elLocale, settingStore.themeConfig.size],
() => {
showSetElGlobel.value = !showSetElGlobel.value;
new Promise<void>((reactive) => reactive()).then(() => (showSetElGlobel.value = !showSetElGlobel.value));
},
);
</script>
<style lang="scss" scoped>
.fade-enter-active,
Expand Down
17 changes: 17 additions & 0 deletions src/setElGlobel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { provideGlobalConfig } from 'element-plus';
import { useSettingStore } from './store';
export default defineComponent({
setup() {
const settingStore = useSettingStore();
provideGlobalConfig(
{
locale: settingStore.elLocale,
size: settingStore.themeConfig.size,
},
undefined,
true,
);
return { template: '<div></div>' };
},
render: () => '',
});

0 comments on commit e5d8039

Please sign in to comment.