fix: 修复改变颜色/模式 出现页面卡死等异常的问题 (#254)

This commit is contained in:
悠静萝莉 2022-08-04 23:56:09 +08:00 committed by GitHub
parent c6806a3140
commit 11f0a1259d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -35,7 +35,7 @@
</template>
<script setup lang="ts">
import { onMounted, watch, ref, onUnmounted, nextTick, computed } from 'vue';
import { onMounted, watch, ref, onUnmounted, nextTick, computed, onDeactivated } from 'vue';
import * as echarts from 'echarts/core';
import { TooltipComponent, LegendComponent, GridComponent } from 'echarts/components';
@ -127,16 +127,21 @@ onUnmounted(() => {
window.removeEventListener('resize', updateContainer);
});
onDeactivated(() => {
storeModeWatch();
storeBrandThemeWatch();
});
const currentMonth = ref(getThisMonth());
watch(
const storeBrandThemeWatch = watch(
() => store.brandTheme,
() => {
changeChartsTheme([monitorChart, countChart]);
},
);
watch(
const storeModeWatch = watch(
() => store.mode,
() => {
[monitorChart, countChart].forEach((item) => {

View File

@ -65,7 +65,7 @@ export default {
</script>
<script setup lang="ts">
import { nextTick, onMounted, onUnmounted, watch, computed } from 'vue';
import { nextTick, onMounted, onUnmounted, watch, computed, onDeactivated } from 'vue';
import * as echarts from 'echarts/core';
import { GridComponent, TooltipComponent, LegendComponent } from 'echarts/components';
@ -133,14 +133,19 @@ onUnmounted(() => {
window.removeEventListener('resize', updateContainer);
});
watch(
onDeactivated(() => {
storeModeWatch();
storeBrandThemeWatch();
});
const storeModeWatch = watch(
() => store.mode,
() => {
renderCharts();
},
);
watch(
const storeBrandThemeWatch = watch(
() => store.brandTheme,
() => {
changeChartsTheme([lineChart, scatterChart]);