Skip to content

Commit 0aaa351

Browse files
authored
fix(vue-pro): fix echarts dom is null on the home page (#129)
1 parent a8373f0 commit 0aaa351

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

packages/toolkits/pro/template/tinyvue/src/views/board/home/components/curve.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
</template>
88

99
<script lang="ts" setup>
10-
import { onMounted, watch, inject } from 'vue';
10+
import { onMounted, watch, inject, ref } from 'vue';
1111
import { useI18n } from 'vue-i18n';
1212
import useLocale from '@/hooks/locale';
1313
1414
const { t } = useI18n();
1515
const { currentLocale } = useLocale();
1616
let echarts = inject<any>('echarts');
17+
const echartsDom = ref();
1718
1819
let option = {
1920
tooltip: {
@@ -185,7 +186,7 @@
185186
};
186187
187188
onMounted(() => {
188-
const chartDom = document.getElementById('line');
189+
const chartDom = echartsDom.value;
189190
const myChart = echarts.init(chartDom as any);
190191
option && myChart.setOption(option);
191192
window.addEventListener('resize', () => {
@@ -194,7 +195,7 @@
194195
});
195196
196197
watch(currentLocale, (newValue, oldValue) => {
197-
const chartDom = document.getElementById('line');
198+
const chartDom = echartsDom.value;
198199
const myChart = echarts.init(chartDom as any);
199200
if (newValue === 'zhCN') {
200201
option.legend.data = ['采样PV', '首屏可见', '页面Onload'];

packages/toolkits/pro/template/tinyvue/src/views/board/home/components/falls.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
</template>
88

99
<script lang="ts" setup>
10-
import { onMounted, watch, inject } from 'vue';
10+
import { onMounted, watch, inject, ref } from 'vue';
1111
import { useI18n } from 'vue-i18n';
1212
import useLocale from '@/hooks/locale';
1313
1414
const { t } = useI18n();
1515
const { currentLocale } = useLocale();
1616
let echarts = inject<any>('echarts');
17+
const echartsDom = ref();
1718
1819
const list = [
1920
{
@@ -167,7 +168,7 @@
167168
};
168169
169170
onMounted(() => {
170-
const chartDom = document.getElementById('flow');
171+
const chartDom = echartsDom.value;
171172
const myChart = echarts.init(chartDom as any);
172173
option && myChart.setOption(option);
173174
window.addEventListener('resize', () => {
@@ -176,7 +177,7 @@
176177
});
177178
178179
watch(currentLocale, (newValue, oldValue) => {
179-
const chartDom = document.getElementById('flow');
180+
const chartDom = echartsDom.value;
180181
const myChart = echarts.init(chartDom as any);
181182
myChart.setOption(option);
182183
});

packages/toolkits/pro/template/tinyvue/src/views/board/home/components/region.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</template>
1515

1616
<script lang="ts" setup>
17-
import { onMounted, inject } from 'vue';
17+
import { onMounted, inject, ref } from 'vue';
1818
import RegionTable from './regiontable.vue';
1919
2020
const data = [
@@ -55,6 +55,7 @@
5555
];
5656
5757
let echarts = inject<any>('echarts');
58+
const echartsDom = ref();
5859
let options = {
5960
tooltip: {
6061
trigger: 'item',
@@ -108,7 +109,7 @@
108109
};
109110
110111
onMounted(() => {
111-
const chartDom = document.getElementById('earth');
112+
const chartDom = echartsDom.value;
112113
const myChart = echarts.init(chartDom as any);
113114
window.addEventListener('resize', () => {
114115
myChart.resize();

packages/toolkits/pro/template/tinyvue/src/views/board/home/components/round.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
</template>
1313

1414
<script lang="ts" setup>
15-
import { onMounted, watch, inject } from 'vue';
15+
import { onMounted, watch, inject, ref } from 'vue';
1616
import { useI18n } from 'vue-i18n';
1717
import useLocale from '@/hooks/locale';
1818
import RoundTable from './roundtable.vue';
1919
2020
const { t } = useI18n();
2121
const { currentLocale } = useLocale();
2222
let echarts = inject<any>('echarts');
23+
const echartsDom = ref();
2324
2425
let option = {
2526
tooltip: {
@@ -67,7 +68,7 @@
6768
};
6869
6970
onMounted(() => {
70-
const chartDom = document.getElementById('circled');
71+
const chartDom = echartsDom.value;
7172
const myChart = echarts.init(chartDom as any);
7273
option && myChart.setOption(option);
7374
window.addEventListener('resize', () => {
@@ -76,7 +77,7 @@
7677
});
7778
7879
watch(currentLocale, (newValue, oldValue) => {
79-
const chartDom = document.getElementById('circled');
80+
const chartDom = echartsDom.value;
8081
const myChart = echarts.init(chartDom as any);
8182
myChart.setOption(option);
8283
});

0 commit comments

Comments
 (0)