Skip to content

Commit

Permalink
fix(vue-pro): fix echarts dom is null on the home page (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
kagol authored Apr 2, 2024
1 parent a8373f0 commit 0aaa351
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
</template>

<script lang="ts" setup>
import { onMounted, watch, inject } from 'vue';
import { onMounted, watch, inject, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import useLocale from '@/hooks/locale';
const { t } = useI18n();
const { currentLocale } = useLocale();
let echarts = inject<any>('echarts');
const echartsDom = ref();
let option = {
tooltip: {
Expand Down Expand Up @@ -185,7 +186,7 @@
};
onMounted(() => {
const chartDom = document.getElementById('line');
const chartDom = echartsDom.value;
const myChart = echarts.init(chartDom as any);
option && myChart.setOption(option);
window.addEventListener('resize', () => {
Expand All @@ -194,7 +195,7 @@
});
watch(currentLocale, (newValue, oldValue) => {
const chartDom = document.getElementById('line');
const chartDom = echartsDom.value;
const myChart = echarts.init(chartDom as any);
if (newValue === 'zhCN') {
option.legend.data = ['采样PV', '首屏可见', '页面Onload'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
</template>

<script lang="ts" setup>
import { onMounted, watch, inject } from 'vue';
import { onMounted, watch, inject, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import useLocale from '@/hooks/locale';
const { t } = useI18n();
const { currentLocale } = useLocale();
let echarts = inject<any>('echarts');
const echartsDom = ref();
const list = [
{
Expand Down Expand Up @@ -167,7 +168,7 @@
};
onMounted(() => {
const chartDom = document.getElementById('flow');
const chartDom = echartsDom.value;
const myChart = echarts.init(chartDom as any);
option && myChart.setOption(option);
window.addEventListener('resize', () => {
Expand All @@ -176,7 +177,7 @@
});
watch(currentLocale, (newValue, oldValue) => {
const chartDom = document.getElementById('flow');
const chartDom = echartsDom.value;
const myChart = echarts.init(chartDom as any);
myChart.setOption(option);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</template>

<script lang="ts" setup>
import { onMounted, inject } from 'vue';
import { onMounted, inject, ref } from 'vue';
import RegionTable from './regiontable.vue';
const data = [
Expand Down Expand Up @@ -55,6 +55,7 @@
];
let echarts = inject<any>('echarts');
const echartsDom = ref();
let options = {
tooltip: {
trigger: 'item',
Expand Down Expand Up @@ -108,7 +109,7 @@
};
onMounted(() => {
const chartDom = document.getElementById('earth');
const chartDom = echartsDom.value;
const myChart = echarts.init(chartDom as any);
window.addEventListener('resize', () => {
myChart.resize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
</template>

<script lang="ts" setup>
import { onMounted, watch, inject } from 'vue';
import { onMounted, watch, inject, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import useLocale from '@/hooks/locale';
import RoundTable from './roundtable.vue';
const { t } = useI18n();
const { currentLocale } = useLocale();
let echarts = inject<any>('echarts');
const echartsDom = ref();
let option = {
tooltip: {
Expand Down Expand Up @@ -67,7 +68,7 @@
};
onMounted(() => {
const chartDom = document.getElementById('circled');
const chartDom = echartsDom.value;
const myChart = echarts.init(chartDom as any);
option && myChart.setOption(option);
window.addEventListener('resize', () => {
Expand All @@ -76,7 +77,7 @@
});
watch(currentLocale, (newValue, oldValue) => {
const chartDom = document.getElementById('circled');
const chartDom = echartsDom.value;
const myChart = echarts.init(chartDom as any);
myChart.setOption(option);
});
Expand Down

0 comments on commit 0aaa351

Please sign in to comment.