Skip to content

Commit 6460c58

Browse files
authored
fix(detail): 解决advanced页面和deploy页面内存泄漏问题 (#917)
- 避免组件卸载后定时器继续执行导致的内存泄漏 - 在 advanced 页面中添加 onUnmounted 钩子清理定时器 - 在 deploy 页面中添加 onUnmounted 钩子清理定时器
1 parent 391796f commit 6460c58

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/pages/detail/advanced/index.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
</div>
132132
</template>
133133
<script setup lang="ts">
134-
import { onMounted, ref } from 'vue';
134+
import { onMounted, onUnmounted, ref } from 'vue';
135135
136136
import { getPurchaseList } from '@/api/detail';
137137
import { t } from '@/locales';
@@ -203,8 +203,9 @@ const pagination = ref({
203203
204204
const updateCurrent = ref(0);
205205
206+
const intervalId = ref();
206207
const stepUpdate = () => {
207-
setInterval(() => {
208+
intervalId.value = setInterval(() => {
208209
if (updateCurrent.value > 5) {
209210
updateCurrent.value = -1;
210211
}
@@ -225,6 +226,12 @@ const fetchData = async () => {
225226
}
226227
};
227228
229+
onUnmounted(() => {
230+
if (intervalId.value) {
231+
clearInterval(intervalId.value);
232+
}
233+
});
234+
228235
onMounted(() => {
229236
stepUpdate();
230237
fetchData();

src/pages/detail/deploy/index.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,12 @@ const visible = ref(false);
163163
// monitorChart logic
164164
let monitorContainer: HTMLElement;
165165
let monitorChart: echarts.ECharts;
166+
const intervalId = ref();
166167
onMounted(() => {
167168
monitorContainer = document.getElementById('monitorContainer');
168169
monitorChart = echarts.init(monitorContainer);
169170
monitorChart.setOption(getSmoothLineDataSet({ ...chartColors.value }));
170-
setInterval(() => {
171+
intervalId.value = setInterval(() => {
171172
monitorChart.setOption(getSmoothLineDataSet({ ...chartColors.value }));
172173
}, 3000);
173174
});
@@ -194,6 +195,9 @@ const updateContainer = () => {
194195
};
195196
196197
onUnmounted(() => {
198+
if (intervalId.value) {
199+
clearInterval(intervalId.value);
200+
}
197201
window.removeEventListener('resize', updateContainer);
198202
});
199203

0 commit comments

Comments
 (0)